Reputation: 1470
I have created one login page with some error message.But I am able to display only single error message.My Requirement is very simple.
I have 2 fields email
and password
when I click go
button if there is no email it should display enter email
.If I have entered invalid email it should display invalid email
.
Similary for password two validation enter password
and enter valid password
.
For this I need to add error messages dynamically.Can anybody help me ?please.
https://jsfiddle.net/jnzk9gv4/
Upvotes: 0
Views: 97
Reputation: 11809
The fastest way here is to simply change the message when you detect a problem.
here you have: https://jsfiddle.net/jnzk9gv4/7/
var error = "";
if (!emailReg.test(userEmail)) {
error = "Invalid email";
} else if (userEmail=="") {
error = "Enter email";
} else if (!passReg.test(userPassword)) {
error = "Invalid password";
} else if (userPassword=="") {
error = "Enter password";
}
if (error != "") {
$("#errorMessage").text(error);
$(".invalidData").show();
} else {
$(".invalidData").hide();
}
Upvotes: 1