VivekMishra

Posts Tagged ‘ASP.Net Server side validation

Make this script according to your need in code this is server side script which use in ASP.Net server side validation

Email validation

<asp:RegularExpressionValidator runat=”server” ID=”rev_email” ControlToValidate=”txt_email” ErrorMessage=”your entry is not a valid email address” ValidationExpression=”.*@.*\..*”>

</asp:RegularExpressionValidator>

<asp:RequiredFieldValidator runat=”server” ID=”rfv_email” ControlToValidate=”txt_email” ErrorMessage=”please enter your email address”></asp:RequiredFieldValidator>

<asp:TextBox ID=”txt_email” runat=”server”></asp:TextBox>

<asp:RegularExpressionValidator ID=”regExEmail” runat=”server” ControlToValidate=”txtEmail” Display=”Dynamic” ErrorMessage=”Please enter a valid Email Address” ValidationExpression=”\w+([-+.’]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*”>

</asp:RegularExpressionValidator>

Blank validation

<asp:RequiredFieldValidator id=”rfv_region_name” runat=”server” ErrorMessage=”Must be select region name” ControlToValidate=”ddl_region”>

</asp:RequiredFieldValidator>

Website validation

<asp:RegularExpressionValidator ID=”reg_website” ControlToValidate=”txt_website” ValidationExpression=”http://(%5B\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?” runat=”server” ErrorMessage=”Invalid URL”>

</asp:RegularExpressionValidator>

File Uloading validation

<asp:RegularExpressionValidator id=”RegularExpressionValidator1″ runat=”server”
ErrorMessage=”Only zip file is allowed!” ValidationExpression =”^.+(.zip|.ZIP)$”
ControlToValidate=”FileUpload1″>

</asp:RegularExpressionValidator>

Phone Number

<asp:RegularExpressionValidator ID=”regExTelephone” runat=”server” ControlToValidate=”txtTelNumber” Display=”Dynamic” ErrorMessage=”Please enter a valid Telephone Number” ValidationExpression=”^(\()?(011|012)(\)|-)?([0-9]{3})?([0-9]{4}|[0-9]{4})$”>

</asp:RegularExpressionValidator>

Numeric value :

<asp:RegularExpressionValidator ID=”regExTelephone” runat=”server” ControlToValidate=”txtTelNumber” Display=”Dynamic” ErrorMessage=”Please enter a valid Telephone Number” ValidationExpression=”^[0-9]$”> </asp:RegularExpressionValidator>

Radio field validation

<asp:RequiredFieldValidator ID=”RequiredFieldValidator2″ runat=”server” ControlToValidate=”Gender” Display=”Dynamic” EnableViewState=”False” ErrorMessage=”Please select one of the ‘Gender’ options”> </asp:RequiredFieldValidator>

<asp:RadioButtonList runat=”server” ID=”Gender” Font-Size=”91%”>

<asp:ListItem Value=”Female” Text=”Female”></asp:ListItem>

<asp:ListItem Value=”Male” Text=”Male”></asp:ListItem>

</asp:RadioButtonList>

If You wand client side validation use java script function .



  • None
  • Mr WordPress: Hi, this is a comment.To delete a comment, just log in, and view the posts' comments, there you will have the option to edit or delete them.

Categories