简体   繁体   中英

alphanumeric validation javascript without regex

if i run, validation just can be work only on symbol "/", if I input the other symbol except / didnt working. I'm not use regex

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;
        }


    }


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

Use .indexOf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM