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 / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

help on regex

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AVL - 05 Jun 2007 14:43 GMT
i want a reg exp for the below format..
1.0.00.0000

i tried as follows
\d\.\d\.\d{2}\.\d{4}

but it's accepting -ves numbers also(-1.0.00.0000)
I want only +ve numbers in my input..how do i check it?
Bryan Phillips - 06 Jun 2007 02:43 GMT
Try this:

[^-]\d\.\d\.\d{2}\.\d{4}

--
Bryan Phillips
MCT, MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com
Web Site:  http://www.composablesystems.net

> i want a reg exp for the below format..
> 1.0.00.0000
[quoted text clipped - 4 lines]
> but it's accepting -ves numbers also(-1.0.00.0000)
> I want only +ve numbers in my input..how do i check it?
OmegaMan - 07 Jun 2007 05:52 GMT
Try this

^(?!\-)\+?\d\.\d\.\d{2}\.\d{4}

I have added the beginning of line ^ and the match invalidator (?! ) which
if the item in the validator matches, the match becomes invalid. Hence if
there is a minus sign, the match is invalid. (Also added \+? which allows for
an optional + sign.

----
Check out MSDN's .Net Regex Forum
http://forums.microsoft.com/MSDN/User/MyForums.aspx?SiteID=1
OmegaMan - 07 Jun 2007 06:01 GMT
Try this

^(?!\-)\+?\d\.\d\.\d{2}\.\d{4}

or if you dont want to enforce the digits, repeat the patter of \d\. such as

^(?!\-)\+?(\d+\.?)+

These concepts are added

^ Beginning of Line to anchor it.
(?! ) Match Invalidator. If the item within matches, it invalidates the
whole match.
      in your case if a - is at the beginning then it will invalidate.
\+?  says look for literal +, zero or 1 item. Just to be consistent.
Alun Harford - 10 Jun 2007 12:58 GMT
> i want a reg exp for the below format..
> 1.0.00.0000
[quoted text clipped - 4 lines]
> but it's accepting -ves numbers also(-1.0.00.0000)
> I want only +ve numbers in my input..how do i check it?

Well that will accept:

foobar fibbles foobar1.0.00.0000foobar fibbles foobar

You're not enforcing matching the beginning and end of the input. Try:

^\d\.\d\.\d{2}\.\d{4}$

Alun Harford

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.