First, need to validate that they are both valid email addresses using Regex
Second, check if they are the same ignoring case, convert both to small case in the function before comparison.
See example:
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
function validateEmails() {
var email1 = document.getElementById("<%=TextBox1.ClientID%>").value.toLowerCase();
var email2 = document.getElementById("<%=TextBox2.ClientID%>").value.toLowerCase();
if (isEmailAddress(email1) && isEmailAddress(email2) && email1 != email2) {
alert("emails are valid and not the same.");
return true;
}
else
alert('email 1 and email 2 are either not valid or they are the same!');
return false;
}
var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
function isEmailAddress(str) {
return str.match(pattern);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" OnClientClick="javascript:return validateEmails();" />
</div>
</form>
</body>
</html>