2

Please help the regex Validator is not work when I click the button .

<div class="panel-body">
                <div class="form-group">
                    <div class="input-group">
                        <asp:Label runat="server" ID="lblAddBranch" Text="Branch Name" 
                           CssClass="text-primary small" AssociatedControlID="txtBranchName" />
                        <asp:RegularExpressionValidator ID="RegExp1"
                          runat="server" ErrorMessage="Branch Name must be between 3 to 12 characters" 
                          ControlToValidate="txtBranchName" ValidationExpression="^[a-zA-Z]{3,12}$" ValidationGroup="grpBranch" />
                    </div>
                    <asp:TextBox runat="server" ID="txtBranchName" CssClass="form-control input-sm" ValidationGroup="grpBranch" />
                </div>
                <asp:Button runat="server" ID="btnAddBranch" Text="Add" CssClass="form-group-btn btn btn-sm btn-primary" 
                  OnClick="btnAddBranch_Click" ValidationGroup="grpBranch" />
            </div>

No Error Message

6
  • Any error you are getting? Commented May 13, 2016 at 5:25
  • ^[a-zA-Z\s]{3,12}$ try this expresseion Commented May 13, 2016 at 6:08
  • When I test it looks like it is working. Can post only abc...z ABC...Z between 3 to 12 chars. Do you want it to do something else? Commented May 13, 2016 at 6:53
  • No errors. Even when the textbox is empty. I even changed the regex validator to a required field one, still nothing Commented May 13, 2016 at 7:18
  • if you put aa in the textbox and press the button you dont get the validation error? Commented May 13, 2016 at 7:45

1 Answer 1

1

Code is working perfect. As per your expression its means that a-z and A-z and 3-12 digit will accept. So when you enter only 12 in your text box the validation will be fire.

To check required field validation you need add Requirefield validation control in you code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.