Validate an Irish mobile phone number

2019-08-05 01:37发布

I want to validate an Irish mobile phone number in the format xxx-xxxxxxx. The first three digits should be 083, 086, 087, or 089. The next seven digits should be integer numbers.

I tried using this HTML5 validation pattern:

<input type="text" id="phone_no" name="owner[phone]" value="" pattern="([0]{1}[8]{1}[3|6|7|9]{1}[0-9]{7})">

The code is not working. How can I validate this information?

3条回答
甜甜的少女心
2楼-- · 2019-08-05 01:41

sorry modify this

function is_phone_number($PhoneNumber)
{
    $formats = array
    (
        '### ## # ### ###', //+265 12 3 456 789
        '############', //265123456789
        '##########', //123456789
        '### # ### ###' //012 3 456 789
    );
    $format = trim(preg_replace('/[0-9]/', '#', $PhoneNumber));
    return (in_array($format, $formats)) ? true : false;
} 
查看更多
Fickle 薄情
3楼-- · 2019-08-05 02:02

fairly old post but this might help anyone still looking for this

/^\s*((\(?(0)\s?8[35679]\)?\s?\d{3}\s?\d{4}))\s*$/
查看更多
放荡不羁爱自由
4楼-- · 2019-08-05 02:05

Anything you put in square brackets translates to "any of these characters".

So 1[abcde]2 is the same as 1(a|b|c|d|e)2

Also, by default a single letter has size one. So [x]{1} is the same as x.

And [0-9] is the same as a digit, which can be expressed as \d

Try this regex, it's easier to understad:

08[3679]-\d{7}
查看更多
登录 后发表回答