Regex help needed
am 02.10.2007 13:19:41 von 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
Re: Regex help needed
am 02.10.2007 14:33:39 von 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?
????
news:1191323981.649551.70690@n39g2000hsh.googlegroups.com...
> 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
>
Re: Regex help needed
am 02.10.2007 15:06:45 von Jesse Houwing
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.
> ????
> news:1191323981.649551.70690@n39g2000hsh.googlegroups.com...
>> 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
>>
--
Jesse Houwing
jesse.houwing at sogeti.nl
Re: Regex help needed
am 02.10.2007 16:37:20 von gilles27
Jesse/cokkiy,
Thanks for your suggestions. That works a treat :-)
Ross