Email validation using jquery on blur event on MVC view page
<div>
<input type='text' id='txtEmail'/>
</div>
//check email id
$("#txtEmail").blur(function () {
var UserEmail = $("#txtEmail").val();
if (UserEmail != "") {
function ValidateEmail(email) {
var expr = /^([\w-\.]+)@@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
return expr.test(email);
};
if (!ValidateEmail(UserEmail)) {
$("#emailError").text("Email is not valid format.").css("color", "red");
$("#emailError").show();
}
else {
$("#emailError").text("Email is valid format.").css("color", "green");
$("#emailError").show();
}
}
});
<div>
<input type='text' id='txtEmail'/>
</div>
//check email id
$("#txtEmail").blur(function () {
var UserEmail = $("#txtEmail").val();
if (UserEmail != "") {
function ValidateEmail(email) {
var expr = /^([\w-\.]+)@@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
return expr.test(email);
};
if (!ValidateEmail(UserEmail)) {
$("#emailError").text("Email is not valid format.").css("color", "red");
$("#emailError").show();
}
else {
$("#emailError").text("Email is valid format.").css("color", "green");
$("#emailError").show();
}
}
});
No comments:
Post a Comment