ludofleury
4/9/2013 - 10:55 AM

regex.php

<?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";
    }
}