This regular expression will not verify if the particular email id exists or not. Instead, this regex is to validate the format of email id
In jquery
var ValidateEmail= function (email)
{
var regexp = new RegExp('^[^\s@]+@[^\s@]+\.[^\s@]+$');
var check = $(email).val();
if (!regexp.test(check)) {
alert('Invalid e-mail!Please enter the e-mail ID in correct format');
$('#EmailID').css('border-color', 'red');
return false;
}
else
{
$('#EmailID').css('border-color', 'green');
return true;
}
}
In HTML
@Html.TextBox("EmailID", null, new { @class = "form-control text-box", @onchange = "ValidateEmail(this)" })
Explanation
This regex is versatile as it allows the all-important international characters while not disturbing the basic something@something.something format.
Leave a comment