Discussion: Regular expression
Afficher un message
Vieux 17/10/2007, 18h55   #2
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Regular expression


<davranfor@gmail.com> wrote in message
news:1192638704.544026.253670@v29g2000prd.googlegr oups.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


  Réponse avec citation
 
Page generated in 0,06616 seconds with 9 queries