RegularExpressionValidator Validation Expression

R

rn5a

A Web Form has a TextBox for users to enter their telephone numbers. I
need to validate the TextBox against 3 conditions - firstly, the
TextBox should allow only whole numbers (from 0 to 9). Secondly, the
minimum allowable length in the TextBox should be greater than or
equal to 8 & lastly the maximum allowable length in the TextBox should
be lesser than or equal to 12. This is how I framed the Validation
Control:

<asp:RegularExpressionValidator ID="regPhone"
ControlToValidate="txtPhone" Display="dynamic" ErrorMessage="Phone No.
Can Have Max. 10 Numbers!" ValidationExpression="[0-9]{8,12}"
runat="server"/>

The above Validation Control does take into account all the 3
conditions stated above but I want the error messages for the 3
conditions to be different. In other words, I want the error messages
to be as precise as possible.

So if a user enters the text "12345678ABC" (without the double quotes)
in the TextBox, the error message should be something like "Phone
number can contain only whole numbers!". On the other hand, if a user
enters the text "12345", the error message should be something like
"Phone number length must atleast be 8!". Or if a user enters the text
"1234567890123456", then the error message should be something like
"Phone number length cannot exceed 12!".

How do I accomplish this?
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

A Web Form has a TextBox for users to enter their telephone numbers. I
need to validate the TextBox against 3 conditions - firstly, the
TextBox should allow only whole numbers (from 0 to 9). Secondly, the
minimum allowable length in the TextBox should be greater than or
equal to 8 & lastly the maximum allowable length in the TextBox should
be lesser than or equal to 12. This is how I framed the Validation
Control:

<asp:RegularExpressionValidator ID="regPhone"
ControlToValidate="txtPhone" Display="dynamic" ErrorMessage="Phone No.
Can Have Max. 10 Numbers!" ValidationExpression="[0-9]{8,12}"
runat="server"/>

The above Validation Control does take into account all the 3
conditions stated above but I want the error messages for the 3
conditions to be different. In other words, I want the error messages
to be as precise as possible.

So if a user enters the text "12345678ABC" (without the double quotes)
in the TextBox, the error message should be something like "Phone
number can contain only whole numbers!". On the other hand, if a user
enters the text "12345", the error message should be something like
"Phone number length must atleast be 8!". Or if a user enters the text
"1234567890123456", then the error message should be something like
"Phone number length cannot exceed 12!".

How do I accomplish this?

You put three validators in the page that each validate one condition
and each have it's own error message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top