Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ <h1>Sign In</h1>
</div>
<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="validator.js" type="text/javascript"></script>
<!-- <script src="validator_coffee.js" type="text/javascript"></script> -->
</body>
</html>
44 changes: 40 additions & 4 deletions validator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
$(document).ready(function() {
$(".errors").children().hide();

//insert your code here

$(function(){
$("form").submit(function() {
validateEmail();
validatePassword();
});

//insert your code here
});

var form = document.forms["sign_in"];

function validateEmail() {
email = /(^[a-z0-9_])+(.|[_])*([a-z0-9])*@([a-z]+).+/;
var validateEmail = form.elements[0].value;
if (validateEmail == null || validateEmail == "") {
$(".errors li:nth-child(1)").show();
}
if (!email) {
$(".errors li:nth-child(1)").show();
}
}

function validatePassword() {
var password = form.elements[1].value;
var hasDigit = /[0-9]/.test(password)
var hasUpper = /[A-Z]/.test(password)
if (password == null || password == "") {
$(".errors li:nth-child(2)").show();
$(".errors li:nth-child(3)").show();
$(".errors li:nth-child(4)").show();
}
if (password.length < 8) {
$(".errors li:nth-child(2)").show();
}
if (!hasUpper) {
$(".errors li:nth-child(3)").show();
}
if (!hasDigit) {
$(".errors li:nth-child(4)").show();
}

}
29 changes: 29 additions & 0 deletions validator_coffee.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
form = document.forms["sign_in"];

$(document).ready ->
$(".errors").children().hide()

$("form").submit ->
validateEmail()
validatePassword()
return

validateEmail = () ->
email = /(^[a-z0-9_])+(.|[_])*([a-z0-9])*@([a-z]+).+/
validateEmail = form.elements[0].value
$(".errors li:nth-child(1)").show() if validateEmail == null || validateEmail == ""
$(".errors li:nth-child(1)").show() if !email
return

validatePassword = () ->
password = form.elements[1].value
hasDigit = /[0-9]/.test(password)
hasUpper = /[A-Z]/.test(password)
if password == null || password == ""
$(".errors li:nth-child(2)").show()
$(".errors li:nth-child(3)").show()
$(".errors li:nth-child(4)").show()
$(".errors li:nth-child(2)").show() if password.length < 8
$(".errors li:nth-child(3)").show() if !hasUpper
$(".errors li:nth-child(4)").show() if !hasDigit
return
48 changes: 48 additions & 0 deletions validator_coffee.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.