Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,59 @@
//insert your code here

$(function(){
$( ".errors li" ).hide();

//insert your code here
$( "form" ).on( "submit", function (event) {
var form_valid = true;
// This could be a resubmit after trying to correct errors
// so we'll hide the errors and let the checks turn them back on.
$( ".errors li" ).hide();

var password = $(this).find( "input[type='password']").first().val();
var email = $(this).find("input[placeholder='Email']").first().val();

if (validate_email(email) == false) {
form_valid = false;
$( ".errors li:nth-child(1)" ).show();
}

if (password_long_enough(password) == false) {
form_valid = false;
$( ".errors li:nth-child(2)" ).show();
}

if (password_with_capital(password) == false) {
form_valid = false;
$( ".errors li:nth-child(3)" ).show();
}

if (password_with_number(password) == false) {
form_valid = false;
$( ".errors li:nth-child(4)" ).show();
}

if (form_valid == false) {
event.preventDefault();
event.stopPropagation();
} else {
alert("I'm submitting it!");
}
});
});

function validate_email(email) {
var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
return reg.test(email);
}

function password_long_enough(password) {
return password.length >= 8;
}

function password_with_capital(password) {
return /[A-Z]/.test(password);
}

function password_with_number(password) {
return /\d/.test(password);
}