|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 ![]() |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
<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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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) |
|
![]() |
| Outils de la discussion | |
|
|