From f9784a50f16c19a26e11b12c425c15e595a36ff3 Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Mon, 8 Jun 2015 14:19:52 -0400 Subject: [PATCH 1/4] write check functions --- validator.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/validator.js b/validator.js index 860dab4..4d589e0 100644 --- a/validator.js +++ b/validator.js @@ -1,7 +1,61 @@ //insert your code here - + $(".errors li").hide(); + $(function(){ - //insert your code here + //Hides all error tags at the beginning + + + $("#").on("submit", function() { + var valid_form = true; + $(".errors li").hide(); + + var email = $(this).find("input[placeholder='Email']").first().val(); + var password = $(this).find("input[placeholder='Password']").first().val(); + + if(!checkEmail(email)){ + valid_form = false; + $(".errors li:nth-child(1)").show(); + } + + if(!check_long_enough(password)){ + valid_form = false; + $(".errors li:nth-child(2)").show(); + } + + if(!check_is_capital(password)){ + valid_form = false; + $(".errors li:nth-child(3)").show(); + } + + if(!check_is_number(password)){ + valid_form = false; + $(".errors li:nth-child(4)").show(); + } + + if(valid_form === false){ + event.preventDefault(); + event.stopPropagation(); + } + else { + + } + }); }); + +function checkEmail(email) { + return /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email); +} + +function check_long_enough(password) { + return password.length() >= 8; +} + +function check_is_capital(password) { + return /[A-Z]/.test(password); +} + +function check_is_number(password) { + return /\d/.test(password); +} From 173b3892f6392e3c9166553c1dbfe95ee50ae6d3 Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Mon, 8 Jun 2015 15:20:45 -0400 Subject: [PATCH 2/4] javascript works, working on rewriting in coffeescript --- validator.coffee | 43 ++++++++++++++++++++ validator.js | 104 ++++++++++++++++++++++------------------------- validatorjs.js | 57 ++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 56 deletions(-) create mode 100644 validator.coffee create mode 100644 validatorjs.js diff --git a/validator.coffee b/validator.coffee new file mode 100644 index 0000000..7694871 --- /dev/null +++ b/validator.coffee @@ -0,0 +1,43 @@ +$(".errors li").hide + +-> + $("form").submit = (event) -> + + is_valid = false + $(".errors li").hide + + email = $("input[placeholder='Email']").val + password = $("input[placeholder='Password']").val + + if !check_email(email) + is_valid = false + $(".errors li:nth-child(1)").show + + if !check_long_enough(password) + is_valid = false + $(".errors li:nth-child(2)").show + + if !check_is_capital(password) + is_valid = false + $(".errors li:nth-child(3)").show + + if !check_is_number(password) + is_valid = false + $(".errors li:nth-child(4)").show + + if !is_valid + event.stopPropagation + event.preventDefault + + +check_email = (email) -> + /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email) + +check_is_number = (password) -> + /\d/.test(password) + +check_long_enough = (password) -> + password.length >= 8; + +check_is_capital = (password) -> + /[A-Z]/.test(password) diff --git a/validator.js b/validator.js index 4d589e0..f088c76 100644 --- a/validator.js +++ b/validator.js @@ -1,61 +1,53 @@ - - //insert your code here - $(".errors li").hide(); - -$(function(){ - - //Hides all error tags at the beginning - - - $("#").on("submit", function() { - var valid_form = true; - $(".errors li").hide(); - - var email = $(this).find("input[placeholder='Email']").first().val(); - var password = $(this).find("input[placeholder='Password']").first().val(); - - if(!checkEmail(email)){ - valid_form = false; - $(".errors li:nth-child(1)").show(); - } - - if(!check_long_enough(password)){ - valid_form = false; - $(".errors li:nth-child(2)").show(); - } - - if(!check_is_capital(password)){ - valid_form = false; - $(".errors li:nth-child(3)").show(); - } - - if(!check_is_number(password)){ - valid_form = false; - $(".errors li:nth-child(4)").show(); - } - - if(valid_form === false){ - event.preventDefault(); - event.stopPropagation(); - } - else { - - } +// Generated by CoffeeScript 1.9.3 +(function() { + var check_email, check_is_capital, check_is_number, check_long_enough; + + $(".errors li").hide; + + (function() { + return $("form").submit = function(event) { + var email, is_valid, password; + is_valid = false; + $(".errors li").hide; + email = $("input[placeholder='Email']").val; + password = $("input[placeholder='Password']").val; + if (!check_email(email)) { + is_valid = false; + $(".errors li:nth-child(1)").show; + } + if (!check_long_enough(password)) { + is_valid = false; + $(".errors li:nth-child(2)").show; + } + if (!check_is_capital(password)) { + is_valid = false; + $(".errors li:nth-child(3)").show; + } + if (!check_is_number(password)) { + is_valid = false; + $(".errors li:nth-child(4)").show; + } + if (!is_valid) { + event.stopPropagation; + return event.preventDefault; + } + }; }); -}); -function checkEmail(email) { - return /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email); -} + check_email = function(email) { + return /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email); + }; + + check_is_number = function(password) { + return /\d/.test(password); + }; -function check_long_enough(password) { - return password.length() >= 8; -} + check_long_enough = function(password) { + return password.length >= 8; + }; -function check_is_capital(password) { - return /[A-Z]/.test(password); -} + check_is_capital = function(password) { + return /[A-Z]/.test(password); + }; -function check_is_number(password) { - return /\d/.test(password); -} +}).call(this); diff --git a/validatorjs.js b/validatorjs.js new file mode 100644 index 0000000..a6f3c9e --- /dev/null +++ b/validatorjs.js @@ -0,0 +1,57 @@ +$(document).on("ready page:load", function() { + $(".errors li").hide(); +}); + +$(function(){ + + + $("form").submit(function(event) { + var is_valid = false; + $(".errors li").hide(); + + var email = $("input[placeholder='Email']").val(); + var password = $("input[placeholder='Password']").val(); + + if(!check_email(email)){ + is_valid = false; + $(".errors li:nth-child(1)").show(); + } + + if(!check_long_enough(password)){ + is_valid = false; + $(".errors li:nth-child(2)").show(); + } + + if(!check_is_capital(password)){ + is_valid = false; + $(".errors li:nth-child(3)").show(); + } + + if(!check_is_number(password)){ + is_valid = false; + $(".errors li:nth-child(4)").show(); + } + + if(!is_valid){ + event.stopPropagation(); + event.preventDefault(); + } + + }); +}); + +function check_email(email) { + return /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email); +} + +function check_long_enough(password) { + return password.length >= 8; +} + +function check_is_capital(password) { + return /[A-Z]/.test(password); +} + +function check_is_number(password) { + return /\d/.test(password); +} From d79fbe1b98383446c3ef2b0667316701e23c68b3 Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Mon, 8 Jun 2015 17:04:36 -0400 Subject: [PATCH 3/4] Continue work on coffeescript, not working --- validator.coffee | 44 +++++++++++++++++++++++------------------- validator.js | 50 +++++++++++++++++++++++++----------------------- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/validator.coffee b/validator.coffee index 7694871..e9a308c 100644 --- a/validator.coffee +++ b/validator.coffee @@ -1,43 +1,47 @@ -$(".errors li").hide +check_email = (email) -> + /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email) + +check_is_number = (password) -> + /\d/.test(password) + +check_long_enough = (password) -> + password.length >= 8; + +check_is_capital = (password) -> + /[A-Z]/.test(password) + +$(document).on 'ready page:load', -> + $('.errors li').hide() + return --> +$ -> $("form").submit = (event) -> is_valid = false $(".errors li").hide - email = $("input[placeholder='Email']").val - password = $("input[placeholder='Password']").val + email = $("input[placeholder='Email']").val() + password = $("input[placeholder='Password']").val() if !check_email(email) is_valid = false - $(".errors li:nth-child(1)").show + $(".errors li:nth-child(1)").show() if !check_long_enough(password) is_valid = false - $(".errors li:nth-child(2)").show + $(".errors li:nth-child(2)").show() if !check_is_capital(password) is_valid = false - $(".errors li:nth-child(3)").show + $(".errors li:nth-child(3)").show() if !check_is_number(password) is_valid = false - $(".errors li:nth-child(4)").show + $(".errors li:nth-child(4)").show() if !is_valid event.stopPropagation event.preventDefault - -check_email = (email) -> - /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email) - -check_is_number = (password) -> - /\d/.test(password) - -check_long_enough = (password) -> - password.length >= 8; - -check_is_capital = (password) -> - /[A-Z]/.test(password) + return + return diff --git a/validator.js b/validator.js index f088c76..1da43ef 100644 --- a/validator.js +++ b/validator.js @@ -2,10 +2,28 @@ (function() { var check_email, check_is_capital, check_is_number, check_long_enough; - $(".errors li").hide; + check_email = function(email) { + return /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email); + }; + + check_is_number = function(password) { + return /\d/.test(password); + }; + + check_long_enough = function(password) { + return password.length >= 8; + }; + + check_is_capital = function(password) { + return /[A-Z]/.test(password); + }; + + $(document).on('ready page:load', function() { + $('.errors li').hide(); + }); - (function() { - return $("form").submit = function(event) { + $(function() { + $("form").submit = function(event) { var email, is_valid, password; is_valid = false; $(".errors li").hide; @@ -13,41 +31,25 @@ password = $("input[placeholder='Password']").val; if (!check_email(email)) { is_valid = false; - $(".errors li:nth-child(1)").show; + $(".errors li:nth-child(1)").show(); } if (!check_long_enough(password)) { is_valid = false; - $(".errors li:nth-child(2)").show; + $(".errors li:nth-child(2)").show(); } if (!check_is_capital(password)) { is_valid = false; - $(".errors li:nth-child(3)").show; + $(".errors li:nth-child(3)").show(); } if (!check_is_number(password)) { is_valid = false; - $(".errors li:nth-child(4)").show; + $(".errors li:nth-child(4)").show(); } if (!is_valid) { event.stopPropagation; - return event.preventDefault; + event.preventDefault; } }; }); - check_email = function(email) { - return /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email); - }; - - check_is_number = function(password) { - return /\d/.test(password); - }; - - check_long_enough = function(password) { - return password.length >= 8; - }; - - check_is_capital = function(password) { - return /[A-Z]/.test(password); - }; - }).call(this); From 595520e1e1512d041241a6d5c95db43bfda33eb6 Mon Sep 17 00:00:00 2001 From: Kaleb Davis Date: Tue, 9 Jun 2015 10:09:29 -0400 Subject: [PATCH 4/4] complete coffeescript version --- validator.coffee | 19 ++++++++----------- validator.js | 26 ++++++++++++-------------- validatorjs.js | 5 ++--- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/validator.coffee b/validator.coffee index e9a308c..5f99510 100644 --- a/validator.coffee +++ b/validator.coffee @@ -1,24 +1,22 @@ check_email = (email) -> /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email) -check_is_number = (password) -> - /\d/.test(password) - check_long_enough = (password) -> password.length >= 8; check_is_capital = (password) -> /[A-Z]/.test(password) -$(document).on 'ready page:load', -> - $('.errors li').hide() - return +check_is_number = (password) -> + /\d/.test(password) + +$('.errors li').hide() $ -> - $("form").submit = (event) -> + $("form").submit (event) -> is_valid = false - $(".errors li").hide + $(".errors li").hide() email = $("input[placeholder='Email']").val() password = $("input[placeholder='Password']").val() @@ -40,8 +38,7 @@ $ -> $(".errors li:nth-child(4)").show() if !is_valid - event.stopPropagation - event.preventDefault - + event.stopPropagation() + event.preventDefault() return return diff --git a/validator.js b/validator.js index 1da43ef..c212a3e 100644 --- a/validator.js +++ b/validator.js @@ -6,10 +6,6 @@ return /[a-zA-Z0-9-._]+@[a-zA-Z0-9-._]+\.[a-zA-Z0-9-._]/.test(email); }; - check_is_number = function(password) { - return /\d/.test(password); - }; - check_long_enough = function(password) { return password.length >= 8; }; @@ -18,17 +14,19 @@ return /[A-Z]/.test(password); }; - $(document).on('ready page:load', function() { - $('.errors li').hide(); - }); + check_is_number = function(password) { + return /\d/.test(password); + }; + + $('.errors li').hide(); $(function() { - $("form").submit = function(event) { + $("form").submit(function(event) { var email, is_valid, password; is_valid = false; - $(".errors li").hide; - email = $("input[placeholder='Email']").val; - password = $("input[placeholder='Password']").val; + $(".errors li").hide(); + email = $("input[placeholder='Email']").val(); + password = $("input[placeholder='Password']").val(); if (!check_email(email)) { is_valid = false; $(".errors li:nth-child(1)").show(); @@ -46,10 +44,10 @@ $(".errors li:nth-child(4)").show(); } if (!is_valid) { - event.stopPropagation; - event.preventDefault; + event.stopPropagation(); + event.preventDefault(); } - }; + }); }); }).call(this); diff --git a/validatorjs.js b/validatorjs.js index a6f3c9e..c251893 100644 --- a/validatorjs.js +++ b/validatorjs.js @@ -1,6 +1,5 @@ -$(document).on("ready page:load", function() { - $(".errors li").hide(); -}); +$(".errors li").hide(); + $(function(){