preg_match

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

preg_match

Post by tores »

Hi.

My problem regards the use of preg_match... I send a variable to a function and then I use preg_match on it.
There are 3 different valid expressions I want to check for.. These are:
xxxxx...-xx...-x...
xxxx-xx-xx-x...
xxxx-xx-xxxx-xx-xx-x...
where "x" is a digit [0-9] and "..." is more digits. The numeric sequences are seperated by "-".
All other expressions should result in an error message.
I know that this can be done with preg_match, but not how... Anyone?

Regards tores
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

is x required digits, and the dots optional?if so

Code: Select all

preg_match('#^([0-9]{5,8}-[0-9]{2,5}-[0-9]{1,4}|[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{1,4}|[0-9]{4}-[0-9]{2}-[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{1,4})$#',$string)
untested
Post Reply