Skip to content

Instantly share code, notes, and snippets.

@joaomosantos
Created December 28, 2017 18:03
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 joaomosantos/1a35a6ac481e6c91bd798e75af3f3bc6 to your computer and use it in GitHub Desktop.
Save joaomosantos/1a35a6ac481e6c91bd798e75af3f3bc6 to your computer and use it in GitHub Desktop.
jQuery Validate
function formValidate() {
$.validator.addMethod("pattern", function(value, element) {
return this.optional(element) || /^\(\d{2}\)\s\d{4,5}-\d{4}$/.test(value);
});
$('#form').validate({
rules: {
nome: "required",
email: {
required: true,
email: true
},
telefone: {
required: true,
pattern: true // addMethod
},
mensagem: "required"
},
messages: {
nome: "Informe seu nome",
email: {
required: "Informe seu e-mail",
email: "Informe um e-mail valido"
},
telefone: {
required: "Informe seu número de contato",
pattern: "Informe um número valido"
},
mensagem: "Informe sua mensagem"
}
});
}
function isSubmit() {
var form = $('#form');
form.validate();
$('#btnenviar').click(function() {
if(form.valid()) {
// true
}
return false;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment