function checkSpaces(elm , fieldName){
var name = elm.value
name = name.replace(/(\s+)+/g," ");
if(name == "" || name == " "){
alert(fieldName +" should not allow empty spaces");
elm.focus();
return true;
}
return false;
}
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; =""
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; =""
Convert to Upper or Lower case in Javascript
function convertToUpper(field){
field.value = field.value.toUpperCase();
field.value = field.value.toLowerCase();
}
field.value = field.value.toUpperCase();
field.value = field.value.toLowerCase();
}
Subscribe to:
Posts (Atom)