Page 1 of 1

Regular Expression to validate

Posted: Thu Aug 12, 2010 8:06 am
by Dev2011
Hi

Suggest a Regular Expression to validate the following criteria:

For a text box,

User can pass

1. empty value or

2. Enter 9 digits or

3. Enter 9 digits followed by comma and space and another set of 9 digits (4 times)

Eg:

User can enter

OR


123456789 OR

123456789, 123456789 OR

123456789, 123456789, 123456789 OR

123456789, 123456789, 123456789, 123456789 OR

123456789, 123456789, 123456789, 123456789, 123456789

Re: Regular Expression to validate

Posted: Thu Aug 12, 2010 9:12 am
by prometheuzz

Code: Select all

$regex = '/^(|\d{9}(, \d{9}){0,4})$/';

Re: Regular Expression to validate

Posted: Thu Aug 12, 2010 10:39 am
by Dev2011
Hi prometheuzz, Thanks.. will try it