Skip to content

Instantly share code, notes, and snippets.

@claudiainbytes
Last active September 6, 2017 18:58
Show Gist options
  • Save claudiainbytes/aa01d2e321a9d1db677f541e0dcaeec7 to your computer and use it in GitHub Desktop.
Save claudiainbytes/aa01d2e321a9d1db677f541e0dcaeec7 to your computer and use it in GitHub Desktop.
customizing jquery form validator cedula and telephone
$.validate({modules : 'date, security', lang: 'es'});
// Add validator
$.formUtils.addValidator({
name : 'cedula',
validatorFunction : function(value, $el, config, language, $form) {
var patt = new RegExp("^[0-9]+$");
if( value.length > 7 && value.length < 13 && patt.test(value) ){
return true;
} else {
return false;
}
},
errorMessage : 'La cédula debe ser númerica y debe contener de 8 a 12 dígitos',
errorMessageKey: 'badCedulaNumber'
});
$.formUtils.addValidator({
name : 'telefono',
validatorFunction : function(value, $el, config, language, $form) {
var patt = new RegExp("^[0-9]+$");
if( value.length > 9 && value.length < 13 && patt.test(value) ){
return true;
} else {
return false;
}
},
errorMessage : 'El teléfono debe ser númerico y debe contener de 10 a 12 dígitos',
errorMessageKey: 'badCedulaNumber'
});
$.formUtils.addValidator({
name : 'customemail',
validatorFunction : function(value, $el, config, language, $form) {
var patt = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if( value.length > 5 && value.length < 100 && patt.test(value) ){
return true;
} else {
return false;
}
},
errorMessage : 'El e-mail no tiene un formato valido',
errorMessageKey: 'badCustomEmail'
});
// Initiate form validation
$.validate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment