regular expression

  • Thread starter Thread starter thomasp
  • Start date Start date
T

thomasp

Can I use a regular expression to test if the entered value is a 4,6,8 or 10
digit number.
If so, could you write a quick example?

1234
123456
12345678
1234567890

It can only be 4,6,8, or 10 digits long and must be all numbers. No
decimals, signs, or spaces.

Thanks,

Thomas
 
This will match only numbers with 4 digits.

^[0-9]{4}$

I couldn't find out how to say 4 or 6 or 8 or 10 :)
 
How about

^(\d\d){2,5}$

that is, 2 3 4 or 5 groups of two digits.


Robin said:
This will match only numbers with 4 digits.

^[0-9]{4}$

I couldn't find out how to say 4 or 6 or 8 or 10 :)


Can I use a regular expression to test if the entered value is a 4,6,8 or
10
digit number.
If so, could you write a quick example?

1234
123456
12345678
1234567890

It can only be 4,6,8, or 10 digits long and must be all numbers. No
decimals, signs, or spaces.

Thanks,

Thomas
 
Thats the one :)

Larry Lard said:
How about

^(\d\d){2,5}$

that is, 2 3 4 or 5 groups of two digits.


Robin said:
This will match only numbers with 4 digits.

^[0-9]{4}$

I couldn't find out how to say 4 or 6 or 8 or 10 :)


Can I use a regular expression to test if the entered value is a 4,6,8
or
10
digit number.
If so, could you write a quick example?

1234
123456
12345678
1234567890

It can only be 4,6,8, or 10 digits long and must be all numbers. No
decimals, signs, or spaces.

Thanks,

Thomas
 
Back
Top