Skip to content

Instantly share code, notes, and snippets.

@thomasv314
Forked from anonymous/gist:4196426
Created December 3, 2012 17:27
Show Gist options
  • Save thomasv314/4196532 to your computer and use it in GitHub Desktop.
Save thomasv314/4196532 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;
$.ajax({
type: 'POST',
url: "checkEmail",
data: value,
success: function(response) {
email_exists = JSON.parse(response.responseText);
},
dataType: dataType
});
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