Regex Help

G

G

Hello,

I have a REGEX validator which checks for DIGITS ONLY, 10 or 11 digits in
length. The pattern is:#

^\d{10,11}$

I would like to enhance this pattern so in addition to only digits, and
string must be 10 or 11 characters in length, - I would like the first
character to be a 0, and the second character must NEVER be a 0.

Matches:
0100000000
01234567890
0101010101

Non Matches:
1000000000
0010000000
1010101010

Any regex pro's here able to assist?

Kind Regards,

Gary.
 
G

Guest

Hello,

I have a REGEX validator which checks for DIGITS ONLY, 10 or 11 digits in
length. The pattern is:#

^\d{10,11}$

I would like to enhance this pattern so in addition to only digits, and
string must be 10 or 11 characters in length, - I would like the first
character to be a 0, and the second character must NEVER be a 0.

Matches:
0100000000
01234567890
0101010101

Non Matches:
1000000000
0010000000
1010101010

Any regex pro's here able to assist?

Kind Regards,

Gary.

^0(?!0)\d{8,9}$
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Alexey said:
^0(?!0)\d{8,9}$

That would be:

^0(?!0)\d{9,10}$

as the look-ahead doesn't consume the character. :)

Here's another way of writing it, perhaps a bit more straight forward:

^0[1-9]\d{8,9}$
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top