Page 1 of 1

preg_match

Posted: Fri Jul 16, 2004 8:51 am
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

Posted: Fri Jul 16, 2004 11:01 am
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