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