Avatar of dmleves49
dmleves49

asked on 

Why Doesn't this regex return a positive result?

I'm not familiar with regex and a temp programmer used this code.
        $pattern = '^[AD]([HF][12]|[Z][1])([0][1234569]|[1][0-9]|[2][123]|[3][34]|[4][0]|[5][1346])([0][12345679]|[1][0])([0][12345]|[1][03]|[2][03679]|[3][2389]|[4][01]|[5][1]|[9][5])([0][0123458]|[1][8]|[2][68]|[3][8]|[4][8]|[H][B])*^';
        
        //check if the product code matches a valid code pattern
        if(!preg_match($pattern, $pc)){
            $error = 'Please enter a valid product code';
        }

Open in new window

$pc is equal to "AF141020100"

I'm wondering if someone could explain how this code does not match the pattern specified.
Programming Languages-OtherDB Dev ToolsPHP

Avatar of undefined
Last Comment
Dan Craciun

8/22/2022 - Mon