After entering an email ID in a textbox, the email validation process is initiated. However, it seems that there is an issue where the entire function may not be executed properly.
<head runat="server">
<title></title>
<script type="text/javascript">
function CheckEmailValidity()
{
var emailInput = document.getElementById('<%=TextBox4.Text %>');<!--TextBox4 captures user input-->
var emailPattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (emailInput.value.length > 0)<!--ensure email field is not empty-->
{
if (emailPattern.test(emailInput.value))
{
return true;
}
else
{
alert("Please enter a valid email address");<!--alert for invalid email input-->
return false;
}
}
else
{
alert("Please enter some text");
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" style="margin-left: 340px" Text="Submit" Width="96px" OnClick="Button1_Click1" OnClientClick="javascript:CheckEmailValidity();"/>
</form>
</body>``