Skip to content

Instantly share code, notes, and snippets.

Created December 3, 2012 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4196426 to your computer and use it in GitHub Desktop.
Save anonymous/4196426 to your computer and use it in GitHub Desktop.
form validator
$(document).ready(function() {
jQuery.validator.addMethod("password", function(value, element) {
var isValid = value.length >= 6 && /\d/.test(value) && /[a-z]/i.test(value);
return isValid;
}, "Password must be at least 8 characters and must contain one number and one character.");
jQuery.validator.addMethod("inUse", function(value, element){
var email_exists = false;
postData = $.post("checkEmail", value);
console.log(email_exists);
postData.error(function() { email_exists = true; });
postData.success(function() { email_exists = false; });
return email_exists;
}, "This email is already in use.");
$("#regie").validate({
rules: {
password: {
password: true,
required: true
},
confirmPass: {
equalTo: "#password"
},
email: {
inUse: true,
required: true,
email: true
},
confirmEmail: {
equalTo: "#email"
},
fName: "required",
lName: "required"
},
messages: {
confirmEmail: {
equalTo: "Please enter the same email."
},
confirmPass: {
equalTo: "Please enter the same password."
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment