How to validate an email address using JavaScript
You can use this code to validate Email ID and Required field validation. Put validation on Text Box. On Click of submit button this code will check whether Text Box is empty or not if Text Box is empty then it show message. It will also check the valid email Id when Text Box has any text in it.
Insert this code between Head section of the Page.
<script language="javascript" type="text/javascript">
//<![CDATA[
function IsValEmail(strControlName)
{
var stremail=document.getElementById(strControlName).value;
if (stremail.length > 0)
{
var rgeExp = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/ ;
if (document.getElementById(strControlName).value.search(rgeExp) < 0)
{
alert("Please enter valid E-mail Id");
return false;
}
else
{
alert("Valid E-mail Id");
return true;
}
}
else
{
alert("Please enter E-mail Id");
return false;
}
}
//]]>
</script>
Insert this code between Body Tag.
<div>
<asp:TextBox ID="txtSubmit" runat="server"></asp:TextBox><asp:Button ID="btnSubmit"
runat="server" OnClientClick="javascript:return IsValEmail('txtSubmit');" Text="Submit" />
</div>
This comment has been removed by the author.
ReplyDeleteInteresting Article
ReplyDeleteJavascript Training in Chennai | HTML5 Online Training | JavaScript Online Training | Javascript Training Courses | Javascript Online Training