RegularExpressionValidator - (.Net 2.0)

M

M. Ali Qureshi

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.
 
M

marss

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
 
M

Mohamad Elarabi

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 ;)
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top