Regular Expression to validate

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
Dev2011
Forum Newbie
Posts: 2
Joined: Thu Aug 12, 2010 8:00 am

Regular Expression to validate

Post 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
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Regular Expression to validate

Post by prometheuzz »

Code: Select all

$regex = '/^(|\d{9}(, \d{9}){0,4})$/';
User avatar
Dev2011
Forum Newbie
Posts: 2
Joined: Thu Aug 12, 2010 8:00 am

Re: Regular Expression to validate

Post by Dev2011 »

Hi prometheuzz, Thanks.. will try it
Post Reply