Step 1: Write JavaScript on the Asp.net page
Between <body> <form>
<Script language = "JavaScript" type = "text/JavaScript">
Function validate ()
...{
If (document. getelementbyid ("txtname"). value = "")
...{
Alert ("name not found ");
Document. getelementbyid ("txtname"). Focus ();
Return false;
}
If (document. getelementbyid ("txtemail"). value = "")
...{
Alert ("email cant not find ");
Document. getelementbyid ("txtemail"). Focus ();
Return false;
}
VaR emailpat = "^ [a-zA-Z0-9 _.] + @ [a-zA-Z0-9-] + [. A-Za-Z] + $ ";
VaR emailid = Document. getelementbyid ("txtemail"). value;
VaR matcharray = emailid. Match (emailpat );
If (matcharray = NULL)
...{
Alert ('your email address seems incorrect. Please try again .');
Document. getelementbyid ("txtemail"). Focus ();
Return false;
}
VaR digits = "0123456789 ";
VaR temp;
For (I = 0; document. getelementbyid ("txtzip"). value. length; I ++)
...{
Temp = Document. getelementbyid ("txtzip"). value. substring (I, I + 1 );
If (digits. indexof (temp) =-1)
...{
Alert ("Please Enter current ZIP Code ");
Document. getelementbyid ("txtzip"). Focus ();
Return false;
}
}
Return true;
}
</SCRIPT>
The second step is to add the following code to the page_load event in. CS:
Protected void page_load (Object sender, eventargs E)
...{
Btnsubmit. Attributes. Add ("onclick", "Return validate ()");
}
In this way, JavaScript can be used for verification.