JQuery Validation for AlphaNumeric Field

Posted on Posted in JQuery

jQuery.validator.addMethod(‘alphanum’, function(value, element)

{
return this.optional(element) || /^[a-z0-9]+$/i.test(value);
}, “This field contain only letters and numbers.”);

 

 

Example:

 

$(‘#frm3’).validate({
rules:
{

roll:
{
alphanum:true

}

}

},
errorClass: ‘help-block’,
errorElement: ‘span’,
highlight: function (element, errorClass, validClass) {
$(element).parents(‘.form-group’).removeClass(‘has-success’).addClass(‘has-error’);
},
unhighlight: function (element, errorClass, validClass) {
$(element).parents(‘.form-group’).removeClass(‘has-error’).addClass(‘has-success’);
}
});

Leave a Reply

Your email address will not be published. Required fields are marked *