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?

Re: help on regex by Bryan

Bryan
Tue Jun 05 20:43:45 CDT 2007

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



"AVL" <AVL@discussions.microsoft.com> wrote in message
news:2102DDD1-1141-4B13-BEDA-4107620213C4@microsoft.com:

> 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?


RE: help on regex by OmegaMan

OmegaMan
Wed Jun 06 23:52:01 CDT 2007

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

RE: help on regex by OmegaMan

OmegaMan
Thu Jun 07 00:01:00 CDT 2007

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.







Re: help on regex by Alun

Alun
Sun Jun 10 06:58:45 CDT 2007

AVL wrote:
> 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?

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