There are lots of mistakes in your code and couple of mistakes in the suggestions from the above members.
I have listed them below.
a) You have to
return the valdiation result (true/false) mandatorily based on the value entered, because you have the OnClientClick function expecting a result.
OnClientClick="return Validate()"
So the validate function needs to return true/false.
b) You have used the RegEx in the wrong manner. You need to place the slashes before and after the regular expression. See the code sample below.
c) When you want to test a Regular Expression , you use the "Test" method of the RegEx object.
See the following modified code snippet with changes.
function Validate() So the validate function needs to return true/false.{
var regVal=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
if (!regVal.test(document.getElementById('<%=TextBox1.ClientID%>').value))
//if match failed than show alert
{
alert("Please Enter Correct Format");
document.getElementById('<%=TextBox1.ClientID%>').focus();
return false;
}
//Add a return true otherwise
return true;
}
Hope this helps.