Leanote's Blog
I love Leanote!
Toggle navigation
Leanote's Blog
Home
Chrome
Git
Linux
Windows
Others
工具大全
VsCode
Expo
Html
JavaScript
Npm
Node
Mock
React-Native
React
TypeScript
小程序
插件
正则
Dva
Ant-Design-React
Umi
Vue
Vux
Ant-Design-Vue
Http
Java
flutter
开发小工具
About Me
Archives
Tags
常用正则语法
2019-11-14 07:46:39
9
0
0
admin
## 匹配空行 > `/^$/` ## 验证只能输入大于0的正整数或者两位小数 > `/^[1-9]+\d*(\.\d{1,2})?$|^0\.([1-9]|\d[1-9])$/.test(value) ` ## 替换为输入大于0的正整数或者两位小数 > `"11".replace(/^([0-9]+\d*(\.\d{1,2})?).*$/, "$1")` ## 验证只能是正负整数或者0 > `/^(0|[1-9][0-9]*|-[1-9][0-9]*)$/` ## input的onkeyup只能输入大于0的正整数 > `String(value).replace(/^[^1-9]|[^0-9]*$/g, "") ` ## 连续三位及以上为重复字 > `/(\w)*(\w)\2{2}(\w)*/g ` ## 二代身份证号码 > `/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/` ## 座机号码(包括分机号码, 如: 0799-7276888-7)/手机号码 > `/^((0\d{2,3}-\d{7,8}(-\d{1})?)|(1[3456789]\d{9}))$/ ` ## 密码8-32位 > `/^\w{8,32}$/` ## 纳税人识别号 > `/[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}/` ## 银行账号 > `/^([1-9]{1})(\d{14}|\d{18})$/` ## 手机号码 > `/^[1](([3|5|8][\d])|([4][4,5,6,7,8,9])|([6][2,5,6,7])|([7][^9])|([9][1,8,9]))[\d]{8}$/` ## 不能连续字符(如123、abc)连续3位或3位以上 ``` export function LxStr(str) { var arr = str.split(''); var flag = true; for (var i = 1; i < arr.length - 1; i++) { var firstIndex = arr[i - 1].charCodeAt(); var secondIndex = arr[i].charCodeAt(); var thirdIndex = arr[i + 1].charCodeAt(); if (firstIndex === secondIndex && secondIndex === thirdIndex) { flag = false; } if ((thirdIndex - secondIndex == 1) && (secondIndex - firstIndex == 1)) { flag = false; } } return flag; // true为不是, false为是 } ```
Pre:
小程序版本自动更新的实现
Next:
0
likes
9
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.