没有正则表达式的字母数字验证javascript

时间:2015-11-30 18:06:47

标签: javascript html validation arraylist alphanumeric

如果我运行,验证只能在符号“/”上工作,如果我输入除/ didnt工作之外的其他符号。我不使用正则表达式

if(nama!==""){
var i;
    var list = new Array ("/","!", "@", "#","$","%","%","^","&","*","(",")","_","+","=","-","`","~",";","<",">",".","?","[","]","{","}",",");

    var llength = list.length;
    for(i=0; i<llength; i++)
    {
        if(nama.match(list[i]))
        {
            alert("Full Name must not contain any number and symbol");
            return false;

        }
        else
        {
            return true;
        }


    }


}

1 个答案:

答案 0 :(得分:3)

    if(nama.indexOf(list[i])!=-1)
    {
        alert("Full Name must not contain any number and symbol");
        return false;
    }
    else
    {
        return true;
    }

使用.indexOf