Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
$pattern = '#^((\+33[\s|\.]?[1-9]{1})|(0\d{1}))([\s|\.]?[0-9]{2})#';
// $pattern = '#^O{1}#';
// $subpattern = '([\s|\.]?[0-9]{2}){8}';
$samples = [
'+33 1 22 33 44 55',
'01 02 03 04 05',
'06 99 99 99 99',
'01.02.03.04.05',
'+33.1.44.55.66.00',
'0145678992'
];
$notsamples = [
'01.02 03 04 05',
'01.02030405',
'+44102030405',
'9966778899'
];
foreach ($samples as $sample) {
if (!preg_match($pattern, $sample)) {
echo 'error, it doesn\'t match: ';
echo $sample;
echo "\r\n";
}
}
foreach ($notsamples as $sample) {
if (preg_match($pattern, $sample)) {
echo 'error, it matches: ';
echo $sample;
echo "\r\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.