Skip to content

Instantly share code, notes, and snippets.

@rafaellyra
Created March 17, 2013 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaellyra/5180792 to your computer and use it in GitHub Desktop.
Save rafaellyra/5180792 to your computer and use it in GitHub Desktop.
Adiciona methodo para validação por regex no plugin jQuery Validate.
$.validator.addMethod('regex', function (value, element, regexp) {
var check = false,
re = new RegExp(regexp);
return this.optional(element) || re.test(value);
}, 'Favor verificar os valores digitados.');
/*
Exemplo de uso :
rules: {
'name': {
required: true,
regex: /^[0-9A-Z]{2}[57C]{1}[0-9A-Z]{14}$/i
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment