用到的正则
Posted web-chuan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用到的正则相关的知识,希望对你有一定的参考价值。
1.数字 大小写字母,特殊字符任意三个:/^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,16}$/
2.包含数字,大写字母,小子字母:/^(?=.*d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Zd]{8,16}$/
3.IP:/^((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]))$/
4.IP段:/^(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d).(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d).(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d).(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d)-(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d).(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d).(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d).(25[0-5]|2[0-4]d|[0-1]d{2}|[1-9]?d)$/
5.端口:/^([0-9]|[1-9]d{1,3}|[1-5]d{4}|6[0-4]d{3}|65[0-4]d{2}|655[0-2]d|6553[0-5])$/
6.允许小数或者整数:/^[0-9]+([.]{1}[0-9]+){0,1}$/
验证密码:不能输入键盘上连续顺序字符的密码(3个以上)
_isKeyBoardContinuousChar(str) { var c1 = [ [‘!‘, ‘@‘, ‘#‘, ‘$‘, ‘%‘, ‘^‘, ‘&‘, ‘*‘, ‘(‘, ‘)‘, ‘_‘, ‘+‘], [‘q‘, ‘w‘, ‘e‘, ‘r‘, ‘t‘, ‘y‘, ‘u‘, ‘i‘, ‘o‘, ‘p‘, ‘{‘, ‘}‘, ‘|‘], [‘a‘, ‘s‘, ‘d‘, ‘f‘, ‘g‘, ‘h‘, ‘j‘, ‘k‘, ‘l‘, ‘:‘, ‘"‘], [‘z‘, ‘x‘, ‘c‘, ‘v‘, ‘b‘, ‘n‘, ‘m‘, ‘<‘, ‘>‘, ‘?‘] ]; var c2 = [ [‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘, ‘9‘, ‘0‘, ‘-‘, ‘=‘], [‘q‘, ‘w‘, ‘e‘, ‘r‘, ‘t‘, ‘y‘, ‘u‘, ‘i‘, ‘o‘, ‘p‘, ‘[‘, ‘]‘, ‘\‘], [‘a‘, ‘s‘, ‘d‘, ‘f‘, ‘g‘, ‘h‘, ‘j‘, ‘k‘, ‘l‘, ‘;‘, ‘‘‘], [‘z‘, ‘x‘, ‘c‘, ‘v‘, ‘b‘, ‘n‘, ‘m‘, ‘,‘, ‘.‘, ‘/‘] ]; str = str.split(""); //获取坐标位置 var y = []; var x = []; for (var c = 0; c < str.length; c++) { y[c] = 0;//当做~`键处理 x[c] = -1; for (var i = 0; i < c1.length; i++) { for (var j = 0; j < c1[i].length; j++) { if (str[c] == c1[i][j]) { y[c] = i; x[c] = j; } } } if (x[c] != -1) continue; for (var i = 0; i < c2.length; i++) { for (var j = 0; j < c2[i].length; j++) { if (str[c] == c2[i][j]) { y[c] = i; x[c] = j; } } } } //匹配坐标连线 for (var c = 1; c < str.length - 1; c++) { if (y[c - 1] == y[c] && y[c] == y[c + 1]) { if ((x[c - 1] + 1 == x[c] && x[c] + 1 == x[c + 1]) || (x[c + 1] + 1 == x[c] && x[c] + 1 == x[c - 1])) { return true; } } else if (x[c - 1] == x[c] && x[c] == x[c + 1]) { if ((y[c - 1] + 1 == y[c] && y[c] + 1 == y[c + 1]) || (y[c + 1] + 1 == y[c] && y[c] + 1 == y[c - 1])) { return true; } } } return false; }