Below is the javascript used to check for a valid email.
var testresults;
function checkEmail() {
var str = document.getElementById('txtMail').value;
alert(str);
var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults = true
else {
radalert("Please input a valid email address!", 300, 100);
testresults = false
}
}
As an alternative you can also use the same Regex check for the valid email using the RegularExpressionValidator validation control in asp.net like
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
Display="Dynamic" ErrorMessage="Please Enter valid Email Address"
ValidationGroup="Email"
ValidationExpression='[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA- Z\.]*[a-zA-Z]'
ControlToValidate="txtMail"
/>
<asp:ImageButton id="btnSendEmail" runat="server" OnClick="btnSendEmail_Click" ImageUrl="~/NewImages/SendButton.png" ValidationGroup="Email" />
Thanks
Mukunda
No comments:
Post a Comment