首页 > 其他 > 详细

正则表达式

时间:2016-05-20 11:24:12      阅读:155      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!