473,491 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

RegularExpressionValidator - (.Net 2.0)

Hi,

I have a text field, where i want the user to add only numbers. The minimum
value should be 1 and there is no limit on maximum value.

I cannot use RangeValidator, because it requires a maximum value as well.

Can i use RegularExpressionValidator for this purpose? Could someone give me
an example of ValidationExpression i should use?

Thanks in advance.

Dec 17 '07 #1
3 4624
You could just write a CustomValidator that checks for an (Integer?) value
greater than zero.

http://msdn2.microsoft.com/en-us/library/f5db6z8k.aspx
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"M. Ali Qureshi" wrote:
Hi,

I have a text field, where i want the user to add only numbers. The minimum
value should be 1 and there is no limit on maximum value.

I cannot use RangeValidator, because it requires a maximum value as well.

Can i use RegularExpressionValidator for this purpose? Could someone give me
an example of ValidationExpression i should use?

Thanks in advance.
Dec 17 '07 #2
On 17 çÒÄ, 15:16, "M. Ali Qureshi" <m.ali.qure...@hotmail.comwrote:
Hi,

I have a text field, where i want the user to add only numbers. The minimum
value should be 1 and there is no limit on maximum value.

I cannot use RangeValidator, because it requires a maximum value as well.

What are you going to do with value from the textbox? If you want to
convert it to a numeric value then a RangeValidator will be good
enough, just set a maximum value to Int32.MaxValue or Int64.MaxValue
according to the required result. In that way, you also check whether
an entered value does not exceed its data type range.

But if you want a string that contains numbers only, starting from 1,
use a RegularExpressionValidator with ValidationExpression =
"[1-9]\d*"

Regards,
Mykola
http://marss.co.ua
Dec 17 '07 #3
You neither need a RegExValidator nor a custom validator for that. The
compareValidator can validate against a constant value. Your tag should look
like this:

<asp:CompareValidator ID="CV1" runat="server"
Type="Double"
Operator="GreaterThanEqual"
ValueToCompare="1"
ControlToValidate="myTextBox"
ErrorMessage="Value must be greater than 0!" />

Hope that works for you. Eid Mubarak ;)

--
Mohamad Elarabi
Lead Developer. MCTS, MCPD.
"M. Ali Qureshi" wrote:
Hi,

I have a text field, where i want the user to add only numbers. The minimum
value should be 1 and there is no limit on maximum value.

I cannot use RangeValidator, because it requires a maximum value as well.

Can i use RegularExpressionValidator for this purpose? Could someone give me
an example of ValidationExpression i should use?

Thanks in advance.
Dec 20 '07 #4

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

Similar topics

0
2992
by: Andy Eshtry | last post by:
I have a radio button list, a textbox representing SIN or EIN based on my radio button list selection so I put 2 regularexpressionvalidator to evaluate the value of textbox. EIN must be (for...
3
3774
by: Ricardo Corsi P. Cesar | last post by:
Hi, i looking for example in asp.net (VB) to make the RegularExpressionValidator in runtime in my code behind. I found some similars codes, but nothing in VB.. thanks!
3
2010
by: DC | last post by:
I have this snippet: <tr> <td align="left">E-mail</td> <td> <asp:TextBox id="txtEmail" runat="server" MaxLength="100"></asp:TextBox>&nbsp; <asp:RegularExpressionValidator id="revEmail"...
0
1339
by: Matt Morris | last post by:
Hello: I have a RegularExpressionValidator control attached to a TextBox. I have the ValidationExpression property set to a very simple validation expression (\w+). The validation always fails...
3
3661
by: tshad | last post by:
I have a RegularExpressionValidator that doesn't seem to work correctly if you don't enter anything. In the following, it works correctly if you have at least 1 character. If you just enter...
0
1138
by: venkat Murthy | last post by:
Hi, I have 10 regularexpression validators in my datagrid. my datagrid looks like; first5controls | boundcolumn | next5controls. Regularexpressionvalidator for first five controls works...
1
1809
by: franz | last post by:
does anybody tell me why it doesn't works?? in any case gg beame true thanks franz Dim y As RegularExpressionValidator = New RegularExpressionValidator y.ValidationExpression =...
1
1469
by: John Yopp | last post by:
I'm trying to use a asp:RegularExpressionValidator to validate the strength of a password. When I test the regular expression with Regex.IsMatch, it works perfectly. However, when used within a...
4
581
by: simonZ | last post by:
I have RegularExpressionValidator which validate one text box. When my text box is validated on client I would like to do something else. Is there some client event of RegularExpressionValidator?...
4
6034
by: =?Utf-8?B?Y3VyaW91cw==?= | last post by:
I am using a RegularExpressionValidator to validate a TextBox. I use "^?+(\.*)?$" to check for a real number. The control works fine as long as the user enters something in the TextBox; it does not...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
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,...
0
7192
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.