写了一个简单的手机号码正则

        /// <summary>
        
/// 检查手机号码和云南省的小灵通
        
/// </summary>
        
/// <param name="pMobile">要检测的手机号码</param>
        
/// <param name="corrertMobile">输出规则手机号码</param>
        
/// <returns></returns>
        public static bool CheckPhone_new(string pMobile,out string corrertMobile)
        {
            
bool isSuccess = false;
            corrertMobile 
= string.Empty;

            
/*
             *首先匹配手机
             * 前面可以为86或者+86或者没有
             * 号段匹配:
             * 13:除了1349(中国卫通,不属于手机号段)
             * 15:全号段匹配 15
             * 18:180(电信),185,186(联通),187,188(移动),189(电信)
             * 
*/
            
if (System.Text.RegularExpressions.Regex.IsMatch(pMobile, @"^(\+?86)?1(3[0-35-9]\d|34[0-8]|5\d{2}|8[05-9]\d)\d{7}$"))
            {
                isSuccess 
= true;
                corrertMobile 
= pMobile.Substring(pMobile.Length - 11);
            }
            
else
            {
                
/*
                 * 小灵通匹配,云南省区号:0691西双版纳,0692德宏
                 * 0870昭通,0871昆明,0872大理,0873红河,0874曲靖,0875保山,0876文山,0877玉溪,0878楚雄,0879普洱
                 * 0883临沧,0886怒江,0887迪庆,0888丽江
                 * 匹配模式868711234567,8608711234567,8610608711234567,10608711234567,08711234567,86前面的+可有可无
                 * 
*/
                
if (System.Text.RegularExpressions.Regex.IsMatch(pMobile, @"^((\+?86)|((\+?86)?(106)?0))(87\d|88[36-8]|69[12])[1-9]\d{6}$"))
                {
                    isSuccess 
= true;
                    corrertMobile 
= "0" + pMobile.Substring(pMobile.Length - 10);
                }
            }

            
return isSuccess;
        }

 

JavaScript

 

// JScript 文件

    
/**
    * 删除左右两端的空格 调用方式 obj.trim()
    
*/
     String.prototype.trim
=function()
    {
        
return this.replace(/(^\s*)|(\s*$)/g,"");
    }

    
function CheckPhone(obj)
    {        
        
var isSuccess=false;
        
        
var mobile=document.getElementById(obj).value;
        mobile
=mobile.trim();
        
var mobileReg=/^(\+?86)?1(3[0-35-9]\d|34[0-8]|5\d{2}|8[05-9]\d)\d{7}$/;
        
var xiaoLingTongReg=/^((\+?86)|((\+?86)?(106)?0))(87\d|88[36-8]|69[12])[1-9]\d{6}$/;        
        
        
/*
         *首先匹配手机
         * 前面可以为86或者+86或者没有
         * 号段匹配:
         * 13:除了1349(中国卫通,不属于手机号段)
         * 15:全号段匹配 15
         * 18:180(电信),185,186(联通),187,188(移动),189(电信)
         * 
*/
        
if(mobileReg.test(mobile))
        {            
            isSuccess
=true;   
            
//赋值,取右边的11位手机号码         
            document.getElementById(obj).value=mobile.substring(mobile.length-11,mobile.length);            
        }
        
else
        {
            
/*
             * 小灵通匹配,云南省区号:0691西双版纳,0692德宏
             * 0870昭通,0871昆明,0872大理,0873红河,0874曲靖,0875保山,0876文山,0877玉溪,0878楚雄,0879普洱
             * 0883临沧,0886怒江,0887迪庆,0888丽江
             * 匹配模式868711234567,8608711234567,8610608711234567,10608711234567,08711234567,86前面的+可有可无
             * 
*/
            
if(xiaoLingTongReg.test(mobile))
            {                             
                isSuccess
=true;
                
//0+右边的10位小灵通号码
                document.getElementById(obj).value="0"+mobile.substring(mobile.length-10,mobile.length);                
            }            
        }
        
        
if(!isSuccess)
        {
            alert(
"请输入正确的手机或者小灵通号码!");
            document.getElementById(obj).focus();
            
        }
        
return isSuccess;
    }

 

posted @ 2009-07-10 23:42  Conan304  阅读(1654)  评论(0编辑  收藏  举报