473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

RegularExpressionValidator Validation Expression

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?

Feb 25 '07 #1
1 13247
rn**@rediffmail.com wrote:
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.

--
Göran Andersson
_____
http://www.guffa.com
Feb 25 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Steve | last post by:
Hi I have a really weird problem and any assistance would be welcome. I have developed an app in Access 2002. The app runs perfectly on the development machine. I have packaged the app using...
1
by: Hai Nguyen | last post by:
I want to validate a textbox with date in the right format. I already have it worked. However, my validation expression does not solve the # of days in Feb; for isntance it does not solve for leap...
3
by: Paul | last post by:
Hi I am using a validationexpression with a regular expression validator. In the properties window for the expression I have |||||||| as I want the following format, abc-efg-hijk-12345-6789 abc...
5
by: JIM.H. | last post by:
Hello, I have this validation expression: ^(?:(?:0?|1)|(?:0?|11)(?!\/31)|(?:0?2)(?:(?!\/3|\/29\/(?:(?:0||)00|(?:\d{2}(?:0||))))))\/(?:0?||3)\/\d{4}$ This is supposed to match MM/DD/YYYY it is...
2
by: pintu | last post by:
Hi I am writing a validation expression for the followings 1)EPF/chp15_v3.htm#p33 or 2)EPF/chp15_v3.htm I wrote the validation expression as *\.(htm|html)\#*$
2
by: pintu | last post by:
Hello every body..First of All Very Very Happy new year to all of u. Today i hav my problem with the validation expression. *\.(htm|html)\#?*$ the above expression works fine for ...
5
by: confused1234 | last post by:
i have a uk validation expression GIR 0AA|({1,2}|(|(|))|) {2}) The line break above is a space. I would like to allow lower case letters aswell. at the moment N19 2UD is correct n19 2ud...
0
by: seng | last post by:
i wanna valid these two input"holland road no.4" and input"hollandroadno.4" allow space,dot,number and alphabet how I can do? give me validation...
1
by: Niluka | last post by:
Hi, I'm using 3 text box controls in asp.net. I want to validate the each text input to this control. I want to give only following characters for 3 text boxes text box 1 = (/\|" text box 2 =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.