From 951bb5b196a871b23c765916b8071f1c7cea52f3 Mon Sep 17 00:00:00 2001 From: Vasanth Pappu Date: Fri, 24 Oct 2014 20:43:31 -0400 Subject: [PATCH 1/5] email validation --- validator.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/validator.js b/validator.js index 860dab4..1701868 100644 --- a/validator.js +++ b/validator.js @@ -4,4 +4,29 @@ $(function(){ //insert your code here + alert("this code being run now"); + + + //$("input[type=submit]").onclick(function({ + //alert("you just pressed a button..."); + //})); +}); + + +$(document).ready(function(){ + $("li").hide(); }); + +$(document).ready(function(){ + $("input[type=submit]").click(function(){ + // RFC 2822 + var reRFC2822 = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/ + if ( reRFC2822.test($("input[type=text]").val()) ) { + $("li:nth-child(1)").hide(); + } else { + $("li:nth-child(1)").show(); + } + + }); +}); + From 54035cc3f73a2dd36a8211056e1be00d0f4529df Mon Sep 17 00:00:00 2001 From: Vasanth Pappu Date: Fri, 24 Oct 2014 21:22:21 -0400 Subject: [PATCH 2/5] the rest of the validations --- validator.js | 62 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/validator.js b/validator.js index 1701868..e588654 100644 --- a/validator.js +++ b/validator.js @@ -1,32 +1,46 @@ - - //insert your code here - -$(function(){ - //insert your code here - alert("this code being run now"); - - - //$("input[type=submit]").onclick(function({ - //alert("you just pressed a button..."); - //})); -}); - - $(document).ready(function(){ $("li").hide(); }); -$(document).ready(function(){ - $("input[type=submit]").click(function(){ - // RFC 2822 - var reRFC2822 = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/ - if ( reRFC2822.test($("input[type=text]").val()) ) { - $("li:nth-child(1)").hide(); - } else { - $("li:nth-child(1)").show(); - } +$(function(){ + //insert your code here + $(document).ready(function(){ + $("input[type=submit]").click(function(){ + // email validation + // RFC 2822 + var reRFC2822 = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/ + if ( reRFC2822.test($("input[type=text]").val()) ) { + $("li:nth-child(1)").hide(); + } else { + $("li:nth-child(1)").show(); + } + + // password length validation + if ($("input[type=password]").val().length < 8) { + $("li:nth-child(2)").show(); + } else { + $("li:nth-child(2)").hide(); + } + + // password capital letter requirement + var passcapre = /[A-Z]/ + if (passcapre.test($("input[type=password]").val()) ) { + $("li:nth-child(3)").hide(); + } else { + $("li:nth-child(3)").show(); + } + + // password number requirement + var passcapre = /[0-9]/ + if (passcapre.test($("input[type=password]").val()) ) { + $("li:nth-child(4)").hide(); + } else { + $("li:nth-child(4)").show(); + } + + }); }); -}); +}); From a3e5685b41b6915739f7d6f14e8e62d55a95302f Mon Sep 17 00:00:00 2001 From: Vasanth Pappu Date: Fri, 24 Oct 2014 21:25:48 -0400 Subject: [PATCH 3/5] document ready was not necessary for hiding li --- validator.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/validator.js b/validator.js index e588654..60d4d11 100644 --- a/validator.js +++ b/validator.js @@ -1,7 +1,5 @@ - //insert your code here -$(document).ready(function(){ - $("li").hide(); -}); +//insert your code here +$("li").hide(); $(function(){ //insert your code here From b1d77b298c985bb8597bfa200ef5e56684198f4a Mon Sep 17 00:00:00 2001 From: Vasanth Pappu Date: Fri, 24 Oct 2014 23:03:28 -0400 Subject: [PATCH 4/5] removed document ready and page makes li elements disappear much faster --- validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validator.js b/validator.js index 60d4d11..96a1927 100644 --- a/validator.js +++ b/validator.js @@ -4,7 +4,7 @@ $("li").hide(); $(function(){ //insert your code here - $(document).ready(function(){ + $(function(){ $("input[type=submit]").click(function(){ // email validation // RFC 2822 From c33993cca1d601ee4ab0d58718cf6ed627169dad Mon Sep 17 00:00:00 2001 From: Vasanth Pappu Date: Fri, 24 Oct 2014 23:07:42 -0400 Subject: [PATCH 5/5] refactored --- validator.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/validator.js b/validator.js index 96a1927..fc1418a 100644 --- a/validator.js +++ b/validator.js @@ -5,18 +5,22 @@ $(function(){ //insert your code here $(function(){ - $("input[type=submit]").click(function(){ + var password = $("input[type=password]") + var submit = $("input[type=submit]") + var email = $("input[type=text]") + + submit.click(function(){ // email validation // RFC 2822 var reRFC2822 = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/ - if ( reRFC2822.test($("input[type=text]").val()) ) { + if ( reRFC2822.test(email.val()) ) { $("li:nth-child(1)").hide(); } else { $("li:nth-child(1)").show(); } // password length validation - if ($("input[type=password]").val().length < 8) { + if (password.val().length < 8) { $("li:nth-child(2)").show(); } else { $("li:nth-child(2)").hide(); @@ -24,7 +28,7 @@ $(function(){ // password capital letter requirement var passcapre = /[A-Z]/ - if (passcapre.test($("input[type=password]").val()) ) { + if (passcapre.test(password.val()) ) { $("li:nth-child(3)").hide(); } else { $("li:nth-child(3)").show(); @@ -32,7 +36,7 @@ $(function(){ // password number requirement var passcapre = /[0-9]/ - if (passcapre.test($("input[type=password]").val()) ) { + if (passcapre.test(password.val()) ) { $("li:nth-child(4)").hide(); } else { $("li:nth-child(4)").show();