0

My textbox should contain 8 digits. If not i want to pop up an alert box. But the regualr expression validator does not trigger. Why?

<asp:LinkButton ID="LinkPayment" CssClass="btn mainBtn" runat="server" onclick="LinkPayment_Click" OnClientClick="_gaq.push(['_trackPageview', '/virtualgoal/smspayment']);">Betal ></asp:LinkButton>  

<asp:RequiredFieldValidator ID="RequiredCustomersPhone" Display="None" ValidationGroup="ValGroupCustomersPhone" ControlToValidate="CustomersPhone" runat="server" ErrorMessage="Du må fylle inn ditt mobilnummer!"></asp:RequiredFieldValidator>   

<asp:RegularExpressionValidator ID="RegExValCustomersPhone" ValidationGroup="ValGroupCustomersPhone" runat="server" ControlToValidate="CustomersPhone" Display="None" ErrorMessage="Telefonnummer må bestå av 8 siffer!" ValidationExpression="[0-9]{8}"></asp:RegularExpressionValidator>

<asp:ValidationSummary ID="ValidationSummary" ShowSummary="False" ValidationGroup="ValGroupCustomersPhone" ShowMessageBox="True" runat="server" /> 
3
  • Does the RequiredFieldValidator trigger? Commented Feb 2, 2012 at 9:27
  • FYI, the first line of your markup is invalid (extra chevron before the closing linkbutton tag). Commented Feb 2, 2012 at 9:29
  • it triggers, but now i see that Page.IsValid returns true Commented Feb 2, 2012 at 9:30

2 Answers 2

3

Add the following code:

ValidationGroup="ValGroupCustomersPhone"

to your linkbutton

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

Comments

0

Are you trying to validate an empty field? You may need a required field validatior as well. It's a shame there is no 'ValidateEmptyText' field on Regex validators.

4 Comments

there is a required field validatior!
@espvar Pardon me, Im being blind :)
Still fair suggestion though, it won't fire if its blank.
Ok, i see what you mean, and I was testing it with content. To few/many digits and chars.

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.