Skip to content
Open
Show file tree
Hide file tree
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
Binary file added node_modules/.DS_Store
Binary file not shown.
69 changes: 65 additions & 4 deletions validator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,68 @@
// $() is an alias for $(document).ready() when you pass it a function

//insert your code here

$(function(){
$(document).ready( function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! My suggestion would be to pull the function definitions for ValidateForm and all of the method's it calls outside of the document ready callback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally makes sense! Done.

$(".errors").children().hide();

//insert your code here
$("form").submit( function() {
ValidateForm();
});
});

function ValidateForm() {
ValidateEmail();
ValidatePassword();
};

function PreventSubmission() {
event.preventDefault();
};

function ValidateEmail() {

var email = $("input:text").val();
var email_regex = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var invalid_format = !email_regex.test(email)

if (invalid_format) {
PreventSubmission;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does your validator prevent submission? I'm not sure it ever gets executed for a couple of reasons.

  1. event in this case would refer to the event argument accepted by the callback function on line 6.
  2. PreventSubmission is different from PreventSubmission(). The first is a reference to the function and the second would execute the function.

esmith_solution_by_eksmith_ pull_request__12 _paircolumbus_formvalidator

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! You are totally right. Thanks for pointing that out. I constantly forget that JS is NOT Ruby.

$(".errors li:nth-child(1)").show();
}
else {
$(".errors li:nth-child(1)").hide();
};
};

function ValidatePassword() {
var password = $("input:password").val();
var capital_regex = /[A-Z]/;
var num_regex = /[0-9]/;
var min_length = 8;
var too_short = password.length < min_length;
var no_capital_chars = !capital_regex.test(password)
var no_numbers = !num_regex.test(password)

if (too_short) {
PreventSubmission();
$(".errors li:nth-child(2)").show();
}
else {
$(".errors li:nth-child(2)").hide();
};


if (no_capital_chars) {
PreventSubmission();
$(".errors li:nth-child(3)").show();
}
else {
$(".errors li:nth-child(3)").hide();
};

if (no_numbers) {
PreventSubmission();
$(".errors li:nth-child(4)").show();
}
else {
$(".errors li:nth-child(4)").hide();
};
};