Showing posts with label how to check alphanumeric value in javascript. Show all posts
Showing posts with label how to check alphanumeric value in javascript. Show all posts

Sunday, July 24, 2011

Check alpha numeric value in javascript.

function isAlphaNumeral(elm,field_name){
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789., ";
    if(!checkChars(elm.value,chars)){
            alert(field_name+" is invalid");
            elm.select();
            return false;
    }
    return true;
}



function checkChars(val,chars){  
    var flag = false;
    for(i=0; i < val.length; i++){
        ch_data = val.charAt(i);
        for(j=0; j
< chars.length; j++){          
            if(ch_data==chars.charAt(j)){
                flag = false;              
                break;
            }
            flag=true;
        }
        if(flag){          
            return false;
        }
    }
    return true;
}< val.length; i++){ < chars.length;    =""