valid_alphanumeric = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ '.,-"; valid_alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ '.,"; valid_email = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ@_-."; valid_numeric = "1234567890"; valid_num = "1234567890 +-"; function check(obg,charset) { var str = obg.value; var new_value=""; for (var i=0; i < str.length; i++) { var letter = str.charAt(i).toUpperCase(); new_value +=letter; } obg.value = new_value; str = new_value; var inv = ""; var vld = ""; var prev = ""; for (var i=0; i < obg.value.length; i++) { var letter = str.charAt(i); if (charset.indexOf(letter) != -1) { if(prev==" " && letter==" ") { } else vld += letter; prev = letter; continue; } else { if(letter==" ") letter = "space"; inv += "["+letter+"] "; } } if(vld==" ") vld=""; obg.value = vld; if(inv!="") { alert_str = "Invalid characters: "+inv; alert_str += "\n------------------------------------------\n"; // alert_str += "Accepting only numeric Characters\n"; // alert_str += "for this field : \n"; // alert_str += "["+charset; // if(charset == valid_alpha) alert_str +=" and space"; // alert_str += "]"; // alert_str += "-------------------------------------------\n"; alert_str += "Removing invalid characters"; alert(alert_str); return false; } }