HighTechTalks DotNet Forums  

RegularExpressionValidator - (.Net 2.0)

ASP.net ASP.net discussions (microsoft.public.dotnet.framework.aspnet)


Discuss RegularExpressionValidator - (.Net 2.0) in the ASP.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
M. Ali Qureshi
 
Posts: n/a

Default RegularExpressionValidator - (.Net 2.0) - 12-17-2007 , 08:16 AM






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.


Reply With Quote
  #2  
Old   
Peter Bromberg [C# MVP]
 
Posts: n/a

Default RE: RegularExpressionValidator - (.Net 2.0) - 12-17-2007 , 12:35 PM






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:

Quote:
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.


Reply With Quote
  #3  
Old   
marss
 
Posts: n/a

Default Re: RegularExpressionValidator - (.Net 2.0) - 12-17-2007 , 03:43 PM



On 17 çÒÄ, 15:16, "M. Ali Qureshi" <m.ali.qure... (AT) hotmail (DOT) com> wrote:
Quote:
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


Reply With Quote
  #4  
Old   
Mohamad Elarabi
 
Posts: n/a

Default RE: RegularExpressionValidator - (.Net 2.0) - 12-19-2007 , 10:37 PM



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:

Quote:
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.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.