Skip to content

Instantly share code, notes, and snippets.

@camiloibarrayepes
Last active June 19, 2018 02:31
Show Gist options
  • Select an option

  • Save camiloibarrayepes/f28103f25507b3c3cd6fc1661ff1c976 to your computer and use it in GitHub Desktop.

Select an option

Save camiloibarrayepes/f28103f25507b3c3cd6fc1661ff1c976 to your computer and use it in GitHub Desktop.
Special Characters Jquery Validation
jQuery.validator.addMethod("nameRegex", function(value, element) {
return this.optional(element) || /^[a-z\ \s]+$/i.test(value);
}, "Name must contain only letters & space");
jQuery("#empform").validate({
rules :{
'name':{
required:true,
nameRegex:true
}
},
messages: {
'name':{
required: "El nombre es obligatorio",
nameRegex: "Solo se permiten letras"
}
}
});
/*----------- Add numbers -----------------*/
jQuery.validator.addMethod("nameRegex", function(value, element) {
return this.optional(element) || /^[a-zA-Z0-9\ \s]+$/i.test(value);
}, "Name must contain only letters & space");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment