Monday, 8 December 2014

Jquery Alphabet Validation

//In text fields enter only alphabets if status is true; otherwise it enters alpha-numeric
function alphabetsValidation(fieldId,status) { $(fieldId).keyup(function(){ var regExp = /^[a-zA-Z]/; // allow only letters var iChars = ""; if(status) iChars = "0123456789!@#$%^&*()+=-_[]\\\';,./{}|\":<>?"; else iChars = "!@#$%^&*()+=-_[]\\\';,./{}|\":<>?"; if (!regExp.test($(fieldId).val())) { $(fieldId).val(''); return false; } else for ( var i = 0; i < $(fieldId).val().length; i++) { if (iChars.indexOf($(fieldId).val().charAt(i)) != -1) { $(fieldId).val(''); return false; } } }); }

No comments:

Post a Comment