码迷,mamicode.com
首页 > 其他好文 > 详细

正则表达式

时间:2016-05-20 11:26:28      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

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))
{

}

 

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; 
       }

  

  

正则表达式

标签:

原文地址:http://www.cnblogs.com/axu92312/p/5511039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!