RegularExpressionValidator - (.Net 2.0)

  • Thread starter Thread starter M. Ali Qureshi
  • Start date Start date
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.
 
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
 
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 ;)
 
Back
Top