Regex help needed

  • Thread starter Thread starter gilles27
  • Start date Start date
G

gilles27

Hi all,

I need a regular expression that will force users to enter 10 or 11
digits, but also allow any amount of spaces anywhere. At the moment
I've got

^[0-9]{10,11}$

which enforces 10 or 11 digits. However as soon as a space is
encountered anywhere, valid input is rejected. Is there any way,
within Regex syntax, to say "ignore spaces"? Examples of input that
should pass are

333 4444 4444
333 333 4444
4444 333 4444
4444 333 333
666666 55555
55555 666666
666666 4444

Any help would be appreciated.

Regards,

Ross
 
You can try this,
^[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]+\s*
But it's very ugly?
 
Hello cokkiy,
You can try this,
^[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]\s*[0-9]
\s*[0-9]\s*[0-9]+\s*
But it's very ugly?

We can ofcourse shorten that a bit:

^\s*(\d\s*){10,11}$

which is a bit more readable.

Hi all,

I need a regular expression that will force users to enter 10 or 11
digits, but also allow any amount of spaces anywhere. At the moment
I've got

^[0-9]{10,11}$

which enforces 10 or 11 digits. However as soon as a space is
encountered anywhere, valid input is rejected. Is there any way,
within Regex syntax, to say "ignore spaces"? Examples of input that
should pass are

333 4444 4444
333 333 4444
4444 333 4444
4444 333 333
666666 55555
55555 666666
666666 4444
Any help would be appreciated.

Regards,

Ross
 

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