- preg_match: documentation ( source)
- printf: documentation ( source)
<?php
$tests = [
'+2347036756899',
'+234-7036-756899',
'+2347036-756899',
'+234-7036756899',
'07036756899',
'0-7036756899',
'07036-756899',
'08036756899',
];
foreach ($tests as $test) {
printf(
"%20s : %s\n",
$test,
preg_match('/^(?:\+234(-)?|0)(?:[78]0|81)\d{2}(?(1)-|)\d{6}$/', $test) ? '✅' : '❌'
);
}