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?
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?