Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icessun/7b48121a73a1b92a71eadf90c805bb7d to your computer and use it in GitHub Desktop.
Save icessun/7b48121a73a1b92a71eadf90c805bb7d to your computer and use it in GitHub Desktop.
1)手机号正则 /^1\d{10}$/
2)有效数字正则 /^[+-]?(\d|([1-9]\d+))(\.\d+)?$/
3)验证年龄 18-65 /^((18|19)|([2-5]\d)|(6[0-5]))$/;
4)验证邮箱的正则 /^([\w.-]+)@([0-9a-zA-Z]+)(\.[a-zA-Z]{2,4}){1,2}$/
5)中文名字 /^[\u4e00-\u9fa5]{2,4}$/
6)身份证号
var reg = /^\d{17}(\d|X)$/;
var reg = /^(\d{2})(\d{4})(\d{4})(\d{2})(\d{2})(\d{2})(\d)(\d|X)$/;
7)非空验证 !/^\s*$/
8)去除首尾空格 /(^ +)|( +$)/g
9)偷小说 /<[^<>]>/g; 注意:textarea 千万不要通过innerHTML取值,因为你拿不到,只能通过value才能内容;
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
10)模板引擎实现原理
var str='my name is {0},my age is {1} , i come form {2}';
11)日期格式化及封装
var strCode='2016-6-23 6:41:30';
2016年6月23 06点41分30秒
12)var str='20160514';
var ary=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖'];
13)var str='全日制第七期学费:14800';
var ary=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖'];
14)敏感词过滤
15)统计出现次数最多的单词(可能是多个),及出现多少次
16)queryURLParameter 获取地址栏中的参数
var str='http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1462967508128_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=%E5%88%98%E8%AF%97%E8%AF%97'
var reg=/(([^?&=]+)=([^?&=]+))/g;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment