Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

RegularExpressionValidator - (.Net 2.0)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
M. Ali Qureshi - 17 Dec 2007 13:16 GMT
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.
Peter Bromberg [C# MVP] - 17 Dec 2007 17:35 GMT
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 

> Hi,
>
[quoted text clipped - 7 lines]
>
> Thanks in advance.
marss - 17 Dec 2007 20:43 GMT
> 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
Mohamad Elarabi - 20 Dec 2007 03:37 GMT
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 ;)

Signature

Mohamad Elarabi
Lead Developer. MCTS, MCPD.

> Hi,
>
[quoted text clipped - 7 lines]
>
> Thanks in advance.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.