diff --git a/coffeevalidator.coffee b/coffeevalidator.coffee new file mode 100644 index 0000000..c24c649 --- /dev/null +++ b/coffeevalidator.coffee @@ -0,0 +1,10 @@ +$(".errors li").hide() + +$("form").submit(() -> + $(".errors li").hide() + text = $("input[type='text']").val(); + pass = $("input[type='password']").val(); + $(".errors li:nth-child(1)").show() if !text.match(/.*@.*\..*/) + $(".errors li:nth-child(2)").show() if pass.length<8 + $(".errors li:nth-child(3)").show() if !pass.match(/.*[A-Z].*/) + $(".errors li:nth-child(4)").show() if !pass.match(/.*[0-9].*/)); \ No newline at end of file diff --git a/coffeevalidator.js b/coffeevalidator.js new file mode 100644 index 0000000..35b6b2d --- /dev/null +++ b/coffeevalidator.js @@ -0,0 +1,24 @@ +// Generated by CoffeeScript 1.9.3 +(function() { + $(".errors li").hide(); + + $("form").submit(function() { + var pass, text; + $(".errors li").hide(); + text = $("input[type='text']").val(); + pass = $("input[type='password']").val(); + if (!text.match(/.*@.*\..*/)) { + $(".errors li:nth-child(1)").show(); + } + if (pass.length < 8) { + $(".errors li:nth-child(2)").show(); + } + if (!pass.match(/.*[A-Z].*/)) { + $(".errors li:nth-child(3)").show(); + } + if (!pass.match(/.*[0-9].*/)) { + return $(".errors li:nth-child(4)").show(); + } + }); + +}).call(this); diff --git a/index.html b/index.html index 7cf849d..76360b4 100644 --- a/index.html +++ b/index.html @@ -28,6 +28,6 @@

Sign In

- + diff --git a/validator.coffee b/validator.coffee new file mode 100644 index 0000000..85ee096 --- /dev/null +++ b/validator.coffee @@ -0,0 +1,12 @@ +$(".errors li").hide() + +$("form").submit(validate); + +validate = () -> + $(".errors li").hide() + text = $("input[type='text']").val(); + pass = $("input[type='password']").val(); + $(".errors li:nth-child(1)").show() if !text.match(/.*@.*\..*/) + $(".errors li:nth-child(2)").show() if pass.length<8 + $(".errors li:nth-child(3)").show() if !pass.match(/.*[A-Z].*/) + $(".errors li:nth-child(4)").show() if !pass.match(/.*[0-9].*/) \ No newline at end of file diff --git a/validator.js b/validator.js index 860dab4..416ce08 100644 --- a/validator.js +++ b/validator.js @@ -1,7 +1,16 @@ +$(".errors li").hide() - //insert your code here - -$(function(){ - - //insert your code here +$("form").submit(function(){ + $(".errors li").hide() + var text = $("input[type='text']").val(); + var pass = $("input[type='password']").val(); + if (!text.match(/.*@.*\..*/)){ + $(".errors li:nth-child(1)").show() + }if(pass.length<8){ + $(".errors li:nth-child(2)").show() + }if(!pass.match(/.*[A-Z].*/)){ + $(".errors li:nth-child(3)").show() + }if(!pass.match(/.*[0-9].*/)){ + $(".errors li:nth-child(4)").show() + } });