-
-
Save tlands/6457801 to your computer and use it in GitHub Desktop.
Form Validation NEED TO REDO THIS OO STYLE ;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$.validator.addMethod("capLetsRegex", function(value) { | |
return /[A-Z]+/.test(value); | |
}, "Password must contain at least one capital letter."); | |
$.validator.addMethod("includeNumeric", function(value) { | |
return /[0-9]+/.test(value); | |
}, "Password must contain at least one number."); | |
$.validator.addMethod("emailRegex", function(value) { | |
return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value); | |
}, "Email must be valid."); | |
$('#signup').validate({ | |
errorLabelContainer: '#errors', | |
wrapper: 'li', | |
onkeyup: false, | |
rules: { | |
email: { | |
emailRegex: true | |
}, | |
password: { | |
required: true, | |
includeNumeric: true, | |
capLetsRegex: true, | |
minlength: 8 | |
}, | |
messages: { | |
email: { | |
emailRegex: "You must have a valid email." | |
}, | |
password: { | |
required: "You need to have a password", | |
includeNumeric: "Your password needs at least one number.", | |
capLetsRegex: "Your password needs at least one capital letter.", | |
minlength: "Your password must be at least 8 characters long." | |
} | |
} | |
} // closing rules | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" href="main.css"> | |
<title>Form Validation</title> | |
</head> | |
<body> | |
<form name="sign_up" action="#" method="post"> | |
<label for="email">Email</label> | |
<input type="text" name="email" /> | |
<label for="password">Password</label> | |
<input type="password" name="password" /> | |
<button type="submit">Sign Up</button> | |
<ul id="errors"></ul> | |
</form><body> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script src="form-validator.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ul#errors { | |
color: red; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment