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
 

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

Back
Top