Regular expression
am 17.10.2007 18:31:44 von davranfor
Hello
I need a regular expression that validate a list of numbers separated
by "-" , numbers can not be greater than 999
Valid examples
0
12-455-01
1-9
125-32-155-45-45
Invalid examples
-1
45-
1-45665456-4
12-45-
-
Thanks ;)
Re: Regular expression
am 17.10.2007 19:55:02 von Steve
wrote in message
news:1192638704.544026.253670@v29g2000prd.googlegroups.com.. .
> Hello
>
> I need a regular expression that validate a list of numbers separated
> by "-" , numbers can not be greater than 999
>
>
> Valid examples
> 0
> 12-455-01
> 1-9
> 125-32-155-45-45
>
> Invalid examples
> -1
> 45-
> 1-45665456-4
> 12-45-
> -
\d{4,}
if you do a preg_match, if any 4 or more contiguous digits are present, you
will get a match...and therefore, your list has numbers in it greater than
999...and is invalid. the dashes, then, become irrelevant.
don't forget, that's just the core pattern...you still need to add the / at
the beginning and end.
hth,
me
Re: Regular expression
am 17.10.2007 21:17:29 von Thomas Mlynarczyk
Also sprach davranfor@gmail.com:
> I need a regular expression that validate a list of numbers separated
> by "-" , numbers can not be greater than 999
/^\d{1,3}(?:-\d{1,3})*$/
Greetings,
Thomas
--
C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)