Created
April 11, 2013 17:54
-
-
Save ConorFl/5365614 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<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> |
This file contains hidden or 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
$("form").submit(function(e){ | |
e.preventDefault(); | |
$("#errors").value = ""; | |
var $e1 = "<li>Must be a valid email address</li>"; | |
var $e2 = "<li>Password must have at least one numeric character (0-9)</li>"; | |
var $e3 = "<li>Password must have at least one capital letter</li>"; | |
var $e4 = "<li>Password must be atleast 8 characters long</li>"; | |
var $email_valid = /.+\@.+\..+/; | |
var $pass_num = /\d/; | |
var $pass_cap = /[A-Z]/; | |
var $pass_eight = /\w\w\w\w\w\w\w\w/; | |
if($email_valid.exec(document.sign_up.email.value) === null) { | |
$($e1).appendTo("#errors"); | |
}; | |
if($pass_num.exec(document.sign_up.password.value) === null) { | |
$($e2).appendTo("#errors"); | |
}; | |
if($pass_cap.exec(document.sign_up.password.value) === null) { | |
$($e3).appendTo("#errors"); | |
}; | |
if($pass_eight.exec(document.sign_up.password.value) === null) { | |
$($e4).appendTo("#errors"); | |
}; | |
}); |
This file contains hidden or 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