php codeigniter中的电话号码验证 [英] Phone number validation in php codeigniter

查看:250
本文介绍了php codeigniter中的电话号码验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了来自此处的手机回拨功能,无法验证。

I have used the call back function for phone no validation from here.

function valid_phone_number_or_empty($value)
{
    $value = trim($value);

    if ($value == '') {
            return TRUE;
    }
    else
    {
            if (preg_match('/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/', $value))
            {
                    return preg_replace('/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/', '($1) $2-$3', $value);
            }
            else
            {
                    return FALSE;
            }
    }
}

但现在的问题是不接受来自欧洲国家和世界其他地区11至13位数的电话号码。任何人都可以为我提供所有国家/地区的所有其他验证。

But now the problem is it doesn't accept phone-no from european countries and other parts of world which are 11 to 13 digits. Can anyone provide me with any other validation for that's universal for all countries?

推荐答案

查看以下内容。 国际电话号码的正规表达式。你需要检查多个正则表达式。如果数字不匹配第一正则表达式(我们的电话号码),然后检查它对国际正则表达式。如果两者都不匹配,则失败测试

take a look at the following. regex for international numbers. You will need to check against multiple regex. If the number does not match the first regex(us phone numbers) then check it against the international regex. If neither match, fail the test

这篇关于php codeigniter中的电话号码验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆