Created
January 16, 2017 13:05
-
-
Save ppxu/308f3917ae9fd9c6cfa74643cb3efb69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 校验密码强度 | |
| // 密码的强度必须是包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间。 | |
| /^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$/ | |
| // 校验中文 | |
| // 字符串仅能是中文。 | |
| /^[\\u4e00-\\u9fa5]{0,}$/ | |
| // 由数字、26个英文字母或下划线组成的字符串 | |
| /^\\w+$/ | |
| // 校验E-Mail 地址 | |
| [\\w!#$%&'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])? | |
| // 校验身份证号码 | |
| // 15位 | |
| /^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$/ | |
| // 18位 | |
| /^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$/ | |
| // 校验日期 | |
| // “yyyy-mm-dd“ 格式的日期校验,已考虑平闰年。 | |
| /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/ | |
| // 校验金额 | |
| // 金额校验,精确到2位小数。 | |
| /^[0-9]+(.[0-9]{2})?$/ | |
| // 校验手机号 | |
| // 国内 13、15、18开头的手机号正则表达式。 | |
| /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$/ | |
| // 判断IE的版本 | |
| /^.*MSIE [5-8](?:\\.[0-9]+)?(?!.*Trident\\/[5-9]\\.0).*$/ | |
| // 校验IP-v4地址 | |
| \\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b | |
| // 校验IP-v6地址 | |
| (([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])) | |
| // 检查URL的前缀 | |
| // 应用开发中很多时候需要区分请求是HTTPS还是HTTP,通过下面的表达式可以取出一个url的前缀然后再逻辑判断。 | |
| if (!s.match(/^[a-zA-Z]+:\\/\\//)) | |
| { | |
| s = 'http://' + s; | |
| } | |
| // 提取URL链接 | |
| ^(f|ht){1}(tp|tps):\\/\\/([\\w-]+\\.)+[\\w-]+(\\/[\\w- ./?%&=]*)? | |
| // 文件路径及扩展名校验 | |
| ^([a-zA-Z]\\:|\\\\)\\\\([^\\\\]+\\\\)*[^\\/:*?"<>|]+\\.txt(l)?$ | |
| // 提取Color Hex Codes | |
| \\#([a-fA-F]|[0-9]){3,6} | |
| // 提取网页图片 | |
| \\< *[img][^\\>]*[src] *= *[\\"\\']{0,1}([^\\"\\'\\ >]*) | |
| // 提取页面超链接 | |
| (<a\\s*(?!.*\\brel=)[^>]*)(href="https?://)((?!(?:(?:www\\.)?'.implode('|(?:www\\.)?', $follow_list).'))[^"]+)"((?!.*\\brel=)[^>]*)(?:[^>]*)></a\\s*(?!.*\\brel=)[^> | |
| // 精炼CSS | |
| // 通过下面的表达式,可以搜索相同属性值的CSS,从而达到精炼代码的目的。 | |
| ^\\s*[a-zA-Z\\-]+\\s*[:]{1}\\s[a-zA-Z0-9\\s.#]+[;]{1} | |
| // 抽取注释 | |
| <!--(.*?)--> | |
| // 匹配HTML标签 | |
| \\s]+))?)+\\s*|\\s*)/?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment