Search code examples
phpstringpreg-match

customizing preg_match


How do i preg_match an string to match the following format in php:

 $m="123/456789/01";

if(pregmatch(????, $m){
   // match
}else{
   // doesn't match
}

i.e. 3 digits + "/" + 6 digits + "/" + 2 digits.


Solution

  • This is my try :)

    if(preg_match('/[0-9]{3}\/[0-9]{6}\/[0-9]{2}/', $m)
    {
        // match
    }
    else
    {
        // Doesn't match
    }