I have a script I have used for quite a while that validates UK postcodes, issue I have is one part of the function uses ereg
rather than preg_match
.
Could someone point me in the right direction with the below please? I have added delimiters but not getting the same results as I was before.
$alpha1 = "[abcdefghijklmnoprstuwyz]";
$alpha2 = "[abcdefghklmnopqrstuvwxy]";
$alpha3 = "[abcdefghjkstuw]";
$alpha4 = "[abehmnprvwxy]";
$alpha5 = "[abdefghjlnpqrstuwxyz]";
// Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
$pcexp[0] = '/^(' . $alpha1 . '{1}' . $alpha2 . '{0,1}[0-9]{1,2})([0-9]{1}' . $alpha5 . '{2})$/';
// Expression for postcodes: ANA NAA
$pcexp[1] = '/^(' . $alpha1 . '{1}[0-9]{1}' . $alpha3 . '{1})([0-9]{1}' . $alpha5 . '{2})$/';
// Expression for postcodes: AANA NAA
$pcexp[2] = '/^(' . $alpha1 . '{1}' . $alpha2 . '[0-9]{1}' . $alpha4 . ')([0-9]{1}' . $alpha5 . '{2})$/';
// Exception for the special postcode GIR 0AA
$pcexp[3] = '/^(gir)(0aa)$/';
// Standard BFPO numbers
$pcexp[4] = '/^(bfpo)([0-9]{1,4})$/';
// c/o BFPO numbers
$pcexp[5] = '/^(bfpo)(c\/o[0-9]{1,3})$/';