Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

识别电话号码,可以是多种格式(转自个人百度空间) #37

Open
mishe opened this issue Dec 3, 2015 · 0 comments
Open

Comments

@mishe
Copy link
Owner

mishe commented Dec 3, 2015

/*
* 识别电话号码,可以是多种格式的:
* 1,区号+号码,可以没有“-”
* 2,号码(7-8位)
* 3,号码-分机号,中间必须有“-”
* 4,区号+号码+分机号
* 5,多个电话号码,每个可以是以上4中之一,可以指定分隔符,默认为“,”分割。
* */

        isPhone=function(v,split){
            split=split||',';
            v=v.split(split);
            for(var i= 0,len= v.length;i<len;i++){
                if(! /^(0\d{2,3})*-?[1-9]\d{6,7}(-\d{1,8})*$/.test(v[i])){
                    return false;
                }
            }
            return true;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant