0

I am trying to ensure that a textbox has at least one number in it with validation in Visual Studio on an ASP.Net webpage. I have gotten it so that the form must allow at least one number in it, however, it also has to have at least 1 alpha character and I would like to allow the user to have the option of only using numbers if they want. I have tried numerous validation input statements but haven't found a way to make it work yet. Thanks for any help you can provide, I am new to this topic and any help you can provide is appreciated.

<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtPassWord" ErrorMessage="Password Must Have a Number" ForeColor="#FF3300" ValidationExpression="(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{1,99})$"></asp:RegularExpressionValidator>
DT74
  • 21
  • 6
  • Try this regex (ValidatorExpression): /^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/ Reference: https://stackoverflow.com/questions/7684815/regex-pattern-to-match-at-least-1-number-and-1-character-in-a-string – Guilherme Martin Sep 28 '19 at 19:38
  • @GuilhermeMartin Thanks for the link, I tried this but it still doesn't allow what I am looking for. Currently, I use: ValidationExpression="(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{1,99})$" and this works for ensuring at least 1 number is there but it also requires 1 alpha. I would like the option for all numbers and no alphas, if that is what the user wants to input. – DT74 Sep 28 '19 at 20:05

0 Answers0