|
Posted by Steve on 10/17/07 17:55
<davranfor@gmail.com> 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
[Back to original message]
|