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

常用正则表达式

时间:2015-04-12 17:39:10      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

正则表达式30分钟入门教程:http://deerchao.net/tutorials/regex/regex.htm
js正则表达式总结:http://bbs.html5cn.org/thread-86756-1-1.html
表单验证常用正则(全):http://www.w3cfuns.com/blog-5437825-5403986.html
 

匹配腾讯QQ号:/^[1-9][0-9]\d{3,8}$/


匹配手机号码:/^1[3|5|8]\d{9}$/
 
匹配中文汉字:/^[\u4e00-\u9fa5]{1,}$/   (至少一次)
 
匹配邮政编码:/^[1-9][0-9]{5}$/;(必须是6位数字,第一位不能为0)
 
匹配网址:/^(http|https|ftp)\:\/\/\w+\.\w+\.\w{2,3}\/$/
 
匹配账号或密码:/^[a-zA-Z_0-9]{6,12}$/   (6-12位字符)
 
匹配邮箱:/^\w+([\-\.]\w+)*@\w+([\-\.]\w+)*\.\w+([\-\.]\w+)*$/;
 
删除首尾空格:
var pattern = /^\s+/;
var str = ‘          goo   gle            ‘;
var result = str.replace(pattern, ‘‘);
pattern = /\s+$/;
result = result.replace(pattern, ‘‘);
alert(result);

常用正则表达式

标签:

原文地址:http://www.cnblogs.com/gyx19930120/p/4419877.html

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