正则表达式

C#
public static Regex regMail = new Regex("^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$"); public static Regex regUserName = new Regex("^[A-Za-z0-9_]+$"); public static Regex regNum = new Regex("^[0-9]*[1-9][0-9]*$"); public static Regex regName = new Regex("^[\u0391-\uFFE5]+$"); public static Regex regMobile = new Regex("^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|17[0-9]{9}|18[0-9]{9}$"); public static Regex regTel = new Regex("\\d{3}-\\d{8}|\\d{4}-\\d{7}"); public static Regex regPostCode = new Regex("[0-9]\\d{5}(?!\\d)"); public static Regex regIndex = new Regex("^(http|https|ftp)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.&%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\'\\/\\+&%\\$#\\=~_\\-@]*)*$");
if (Exec.regMobile.IsMatch(mo))
{

}

去除空格 return str.replace(/(^\s*)|(\s*$)/g, ""); 

 

JS:

function validatemobile(mobile) 
   { 
       if(mobile.length==0) 
       { 
          alert('请输入手机号码!'); 
          document.form1.mobile.focus(); 
          return false; 
       }     
       if(mobile.length!=11) 
       { 
           alert('请输入有效的手机号码!'); 
           document.form1.mobile.focus(); 
           return false; 
       } 
        
       var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; 
       if(!myreg.test(mobile)) 
       { 
           alert('请输入有效的手机号码!'); 
           document.form1.mobile.focus(); 
           return false; 
       }

  

  

posted @ 2016-05-20 09:47  阿旭92312  阅读(140)  评论(0编辑  收藏  举报