Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

Is this a proper RegularExpressionValidator for ONLY Numeric values and Dashes: ValidationExpression="/(^[0-9]+([-]*[0-9]+)*$)/"

In an aspx file for an ASP.Net application, is this a proper RegularExpressionValidator for verifying only Numeric values and Dashes:

ValidationExpression="/(^[0-9]+([-]*[0-9]+)*$)/"

The acceptable values are:

624-018867-0
734031514-0
004-110077
107671
010115018

 <tr>
                       <td align="left" width="50%"  style="font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: bold;
                            font-style: normal; color: #00356A; " class="auto-style1" >Account Numb:
                        <asp:TextBox ID="txtAccntnum" Maxlength="15" runat="server" style="margin-left: 0px;text-align: left;" Width="15%"  AutoPostBack="true" ></asp:TextBox>    
                        <asp:RegularExpressionValidator ID="RegularExpressionValidatorAccount" runat="server"
                        ErrorMessage="Account Invalid. Enter numbers and hyphens."
                        ControlToValidate="txtAccntnum"
                        ValidationExpression="/(^[0-9]+([-]*[0-9]+)*$)/">
                        </asp:RegularExpressionValidator>
                       </td>
                     </tr>
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Terry Woods
Yes, your description is correct.

  • It requires at least one digit
  • It allows hyphen characters, but even though multiple hyphen characters are allowed (even in a row like 1---23 ) there must always be at least one digit after them