From d9d8cdf08269bc3583e412ecd9246ccf27faa190 Mon Sep 17 00:00:00 2001 From: degoeym Date: Wed, 22 Oct 2014 23:19:15 -0400 Subject: [PATCH 1/2] Checking in solution --- validator.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/validator.js b/validator.js index 860dab4..bc0ad0e 100644 --- a/validator.js +++ b/validator.js @@ -1,7 +1,32 @@ - - //insert your code here - $(function(){ + $('li').hide(); + + $('input[type=submit]').click(function () { + var email = $('input[type=text]').val().toString(); + var password = $('input[type=password]').val().toString(); + + if (!email.match(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/)) { + $('ul li:nth-child(1)').slideDown('slow'); + } else { + $('ul li:nth-child(1)').slideUp('slow'); + } + + if (password.length < 8) { + $('ul li:nth-child(2)').slideDown('slow'); + } else { + $('ul li:nth-child(2)').slideUp('slow'); + } + + if (!password.match(/^(?=.*[A-Z]).+$/)) { + $('ul li:nth-child(3)').slideDown('slow'); + } else { + $('ul li:nth-child(3)').slideUp('slow'); + } - //insert your code here + if (!password.match(/.*[0-9].*/)) { + $('ul li:nth-child(4)').slideDown('slow'); + } else { + $('ul li:nth-child(4)').slideUp('slow'); + } + }); }); From c652bad621b657ee7e314b151a9cfbc7ca9f0530 Mon Sep 17 00:00:00 2001 From: Matt DeGoey Date: Thu, 23 Oct 2014 19:31:19 +0000 Subject: [PATCH 2/2] Redid with ternary operator because I can and I was bored. --- validator.js | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/validator.js b/validator.js index bc0ad0e..b5b56c9 100644 --- a/validator.js +++ b/validator.js @@ -1,3 +1,11 @@ +function Show(position) { + +} + +function Hide() { + +} + $(function(){ $('li').hide(); @@ -5,28 +13,9 @@ $(function(){ var email = $('input[type=text]').val().toString(); var password = $('input[type=password]').val().toString(); - if (!email.match(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/)) { - $('ul li:nth-child(1)').slideDown('slow'); - } else { - $('ul li:nth-child(1)').slideUp('slow'); - } - - if (password.length < 8) { - $('ul li:nth-child(2)').slideDown('slow'); - } else { - $('ul li:nth-child(2)').slideUp('slow'); - } - - if (!password.match(/^(?=.*[A-Z]).+$/)) { - $('ul li:nth-child(3)').slideDown('slow'); - } else { - $('ul li:nth-child(3)').slideUp('slow'); - } - - if (!password.match(/.*[0-9].*/)) { - $('ul li:nth-child(4)').slideDown('slow'); - } else { - $('ul li:nth-child(4)').slideUp('slow'); - } + var isEmail = !email.match(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/) ? $('ul li:nth-child(1)').slideDown('slow') : $('ul li:nth-child(1)').slideUp('slow'); + var passwordLength = password.length < 8 ? $('ul li:nth-child(2)').slideDown('slow') : $('ul li:nth-child(2)').slideUp('slow'); + var hasCapLetter = !password.match(/^(?=.*[A-Z]).+$/) ? $('ul li:nth-child(3)').slideDown('slow') : $('ul li:nth-child(3)').slideUp('slow'); + var hasNumber = !password.match(/.*[0-9].*/) ? $('ul li:nth-child(4)').slideDown('slow') : $('ul li:nth-child(4)').slideUp('slow'); }); });