Skip to content

Instantly share code, notes, and snippets.

@ludofleury
Created April 9, 2013 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ludofleury/5344815 to your computer and use it in GitHub Desktop.
Save ludofleury/5344815 to your computer and use it in GitHub Desktop.
<?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