Rangevalidator: Enter an integer between 0 and 100 (VB.net) : RangeValidator « Validation by Control « ASP.Net






Rangevalidator: Enter an integer between 0 and 100 (VB.net)

<%@ Page Language="vb" %>
<html>
<head>
   <title>Validation Control Example</title>
    <script language="javascript">
    <!--
      function ClientValidate(source, arguments)
      {
         //alert(arguments.Value);
         var r, re;      //Declare variables.
         re = new RegExp(/^[1-9][0-9][0-9][0-9]$/);  //Create regular expression object.
         r = re.test(arguments.Value);  //Test for match.
         arguments.IsValid = r;    //Return results.
      }
   -->
   </script>
   <script runat="server">
      Sub Page_Load()
         vsSummary.DisplayMode = ValidationSummaryDisplayMode.List
      End Sub
      Sub ServerValidation (source As object, args As ServerValidateEventArgs)
         Dim RegExVal As New System.Text.RegularExpressions.Regex("^\d{4}$")
         If RegExVal.IsMatch(args.Value) Then
            args.IsValid = True
         Else
            args.IsValid = False
         End If
      End Sub
   </script>
</head>
<body>
   <h1>Validation Control Example</h1>
   <form runat="server">
      <asp:table id="MyTable" border="1" cellpadding="5" cellspacing="0" runat="server">
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               CustomValidator Control:
               <br><br>
               Enter a 4-digit year
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:textbox id="year" runat="server"/><br>
               <asp:customvalidator id="cvDate" 
                  controltovalidate="year"
                  errormessage="Not a valid year!"
                  onservervalidate="servervalidation"
                  clientvalidationfunction="ClientValidate"
                  display="dynamic"
                  runat="server"/>
            </asp:tablecell>
         </asp:tablerow>
         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               RangeValidator Control:
               <br><br>
               Enter an integer between 0 and 100
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:textbox id="value" runat="server"/><br>
               <asp:rangevalidator id="rvCompare"
                  controltovalidate="value" 
                  minimumvalue="0"
                  maximumvalue="100" 
                  type="integer" 
                  errormessage="Value not in valid range!" 
                  runat="server"/>
            </asp:tablecell>
         </asp:tablerow>


         <asp:tablerow runat="server">
            <asp:tablecell runat="server">
               ValidationSummary Control:
            </asp:tablecell>
            <asp:tablecell runat="server">
               <asp:validationsummary id="vsSummary"
                  displaymode="bulletlist" 
                  headertext="Page has the following errors: "
                  showsummary="true" 
                  showmessagebox="false"
                  runat="server"/>
            </asp:tablecell>
         </asp:tablerow>
         <asp:tablerow runat="server">
            <asp:tablecell colspan="2" runat="server">
               <asp:button text="submit" runat="server"/>
            </asp:tablecell>
         </asp:tablerow>
      </asp:table>
      <asp:label id="MyLabel" runat="server"/>
   </form>
</body>
</html>

           
       








Related examples in the same category

1.Validation test: range (C#)
2.RangeValidator Demo: The Quantity field must be from 1 to 30! (VB.net)
3.Range validator for Date type value
4.RangeValidator for integer type value
5.Set Focus On Error