Asp. NET Learning Notes: Validating user Form input

Source: Internet
Author: User

Operating environment: Win2000 Advance server+iis5.0+ngws SDK (80M).
The function of verifying the email address is in the code of Brother Liao's essence area.
<%@ Page language= "C #"%>

<script language= "JavaScript" >
function Clientvalidateemail (source, value)
{
var strr;
re=/(\w+@\w+\.\w+) (\.{ 0,1}\w*) (\.{ 0,1}\w*)/I;
Re.exec (value);
if (regexp.$3!= "&&regexp.$3!=".) &&regexp.$2!= ".") Strr=regexp.$1+regexp.$2+regexp.$3
Else
if (regexp.$2!= "" &&regexp.$2!= ".") Strr=regexp.$1+regexp.$2
else strr=regexp.$1
if (Strr!=value)
return false;
Else
return true;
}
</script>
<body>


<form Method=post runat=server>
&LT;HR width=600 size=1 noshade>
<table>
<tr>
<td>
<asp:validationsummary id= "valsum" runat= "Server"
headertext= "You must enter the following form fields:"
Displaymode= "BulletList"
Font-name= "Song Body"
Font-size= "12"
/>
</td>
</tr>
</table>
<center>
<p>

<!--login information-->
<table border=0 width=600 >
&LT;TR&GT;&LT;TD colspan=3>
<table border=0 cellpadding=0 cellspacing=0 width= "100%" >
<tr><td>
<b> Login Information </b>
</td></tr>
</table>
</td></tr>
<tr>
&LT;TD align=right>
Email Address:
</td>
<td>
<asp:textbox id=email width=200px maxlength=60 runat=server/>
</td>
<td>
<asp:requiredfieldvalidator id= "Emailreqval"
controltovalidate= "Email"
errormessage= "Email Address"
Display= "Dynamic"
Font-name= "Song Body"
Font-size= "12"
Runat=server>
*
</asp:RequiredFieldValidator>
<asp:customvalidator id= "Emailregexval" runat= "Server"
controltovalidate= "Email"
clientvalidationfunction= "Clientvalidateemail"

Display= "Static"
Font-name= "Song Body"
Font-size= ">"
Illegal email address
</asp:CustomValidator>
</td>
</tr>

<tr>
&LT;TD align=right>
Password:
</td>
<td>
<asp:textbox id=passwd textmode= "Password" maxlength=20 runat=server/>
</td>
<td>
<asp:requiredfieldvalidator id= "Passwdreqval"
Controltovalidate= "passwd"
errormessage= "User Password"
Display= "Dynamic"
Font-name= "Song Body" font-size= "12"
Runat=server>
*
</asp:RequiredFieldValidator>
<asp:regularexpressionvalidator id= "Passwdregexbal"
Controltovalidate= "passwd"
Validationexpression= ". *[!@#$%^&*+;:].*"
Display= "Static"
Font-name= "Song Body" font-size= "12"
Width= "100%" runat=server>
The password must contain the following characters: (!@#$%^&*+;:)
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
&LT;TD align=right>
Confirm Password
</td>
<td>
<asp:textbox id=passwd2 textmode= "Password" maxlength=20 runat=server/>
</td>
<td>
<asp:requiredfieldvalidator id= "Passwd2reqval"
Controltovalidate= "Passwd2"
errormessage= "Confirm Password"
Display= "Dynamic"
Font-name= "Song Body" font-size= "12"
Runat=server>
*
</asp:RequiredFieldValidator>
<asp:comparevalidator id= "CompareValidator1"
Controltovalidate= "Passwd2" controltocompare= "passwd"
Display= "Static"
Font-name= "Song Body" font-size= "12"
Runat=server>
Password does not match
</asp:CompareValidator>
</td>
</tr>
&LT;TR&GT;&LT;TD colspan=3> </td></tr>


<!--private information-->
&LT;TR&GT;&LT;TD colspan=3>
<table border=0 cellpadding=0 cellspacing=0 width= "100%" >
<tr><td>
<b> Personal Information </b>
</td></tr>
</table>
</td></tr>
<tr>
&LT;TD align=right>
Name:
</td>
<td>
<asp:textbox id=pname maxlength=20 width=200px runat=server/>
</td>
<td>
</td>
</tr>
<tr>
&LT;TD align=right>
Address:
</td>
<td>
<asp:textbox id=address width=200px runat=server/>
</td>
<td>
</td>
</tr>
<tr>
&LT;TD align=right>
Zip:
</td>
<td>
<asp:textbox id=postcode width=60px maxlength=6 runat=server/>
</td>
<td>
<asp:regularexpressionvalidator id= "RegularExpressionValidator1"
Controltovalidate= "Postcode"
validationexpression= "^\d{6}$"
Display= "Static"
Font-name= "Song Body" font-size= "12"
Runat=server>
Zip code must be 6 digits
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
&LT;TD align=right>
Gender:
</td>
<td>
<asp:radiobuttonlist Id=sextype runat=server>
<asp:ListItem> male </asp:ListItem>
<asp:ListItem> Women </asp:ListItem>
</ASP:RadioButtonList>
</td>
<td>
<asp:requiredfieldvalidator id= "Sextypereqval"
Controltovalidate= "Sextype"
Errormessage= "Gender"
Display= "Static"
Initialvalue= ""
Font-name= "Song Body" font-size= "12"
Runat=server>
*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
&LT;TD align=right>
Year of birth:
</td>
<td>
<asp:dropdownlist Id=expyear runat=server>
<asp:ListItem></asp:ListItem>
<asp:listitem >1976</asp:ListItem>
<asp:listitem >1975</asp:ListItem>
</ASP:DropDownList>
</td>
<td>
<asp:requiredfieldvalidator id= "Expdatereqval"
Controltovalidate= "Expyear"
Errormessage= "Year of Birth"
Display= "Static"
Initialvalue= ""
Font-name= "Song Body" font-size= "12"
Runat=server>
*
</asp:RequiredFieldValidator>
</td>
</tr>
</table>

<p>
<input runat= "Server" Type=submit value= "Submit" >
<p>
</form>
</center>
</body>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.