diff --git a/validator.coffee b/validator.coffee new file mode 100644 index 0000000..bc5a2bc --- /dev/null +++ b/validator.coffee @@ -0,0 +1,22 @@ +$('ul.errors li').hide() + +$ -> + $('form').submit -> + $('ul.errors li').hide() + + # validate email + email = $('input[type="text"]').val(); + email_test = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/ + if !email_test.test(email) + $('ul li:first-child').show() + + # validate password + password = $('input[type="password"]').val() + if password.length < 8 + $('ul li:nth-child(2)').show() + if password == password.toLowerCase() + $('ul li:nth-child(3)').show() + if password == password.replace(/[0-9]/g, ' ') + $('ul li:nth-child(4)').show() + return + return diff --git a/validator.js b/validator.js index 860dab4..10bcf08 100644 --- a/validator.js +++ b/validator.js @@ -1,7 +1,27 @@ +// Generated by CoffeeScript 1.10.0 +(function() { + $('ul.errors li').hide(); - //insert your code here - -$(function(){ + $(function() { + $('form').submit(function() { + var email, email_test, password; + $('ul.errors li').hide(); + email = $('input[type="text"]').val(); + email_test = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/; + if (!email_test.test(email)) { + $('ul li:first-child').show(); + } + password = $('input[type="password"]').val(); + if (password.length < 8) { + $('ul li:nth-child(2)').show(); + } + if (password === password.toLowerCase()) { + $('ul li:nth-child(3)').show(); + } + if (password === password.replace(/[0-9]/g, ' ')) { + $('ul li:nth-child(4)').show(); + } + }); + }); - //insert your code here -}); +}).call(this);