...

View Full Version : whats the regex for this express ??



PHPycho
04-20-2007, 08:45 AM
Knock Knock
Help again..
Whats the regex for the format like

883 02 12313545

or

883-02-12313545

GJay
04-20-2007, 08:55 AM
3 numbers:
[0-9]{3}

a dash or a space:
[- ]

2 numbers:
[0-9]{2}

a dash or a space:
[- ]

8 numbers:
[0-9]{8}

so together:
/[0-9]{3}[- ][0-9]{2}[- ][0-9]{8}/

should do it

Philip M
04-20-2007, 06:14 PM
Better to put the ^ and $ in to pass ONLY this pattern of numbers (and not e.g. abc 123 12 12345678 xyz)

/^[0-9]{3}[- ][0-9]{2}[- ][0-9]{8}$/

If you wish you can make the hyphens and/or spaces optional with

/^[0-9]{3}[- ]?[0-9]{2}[- ]?[0-9]{8}$/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum