密码的正则表达式,包含至少2个大写字母,2个小写字母,2个符号和2个任意顺序的数字 [英] Regular expression for a password containing at least 2 uppercase letters, 2 lowercase letters, 2 symbols, and 2 numbers in any sequence
本文介绍了密码的正则表达式,包含至少2个大写字母,2个小写字母,2个符号和2个任意顺序的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我与RegEx()一起使用时,这在JavaScript密码验证中不起作用:
This is not working in JavaScript password validation when I am using it with RegEx():
(?=(.*\\d){2,})(?=(.*[A-Z]){2,})(?=(.*[a-z]){2,})(?=(.*[!@#$%^&*?]){2,})(?!.*[\\s])^.*
推荐答案
在这里:
我使用的正则表达式是:
Here you go:
The regex that I've used is:
1)(?=(. \ d){2})->至少2位数字
2)(?=(. [a-z]){2})->至少2个小写字符
3)(?=(. [A-Z]){2})->至少2个大写字符
4)(?=(. [!@#$%]){2})->至少2个特殊字符,可以是!,@,#,$,%
1) (?=(.\d){2}) --> atleast 2 digits
2) (?=(.[a-z]){2}) --> atleast 2 lower case chars
3) (?=(.[A-Z]){2}) --> atleast 2 upper case chars
4) (?=(.[!@#$%]){2}) --> atleast 2 special chars, can be any one of !, @, #, $, %
angular.module('myApp', [])
.controller('MyController', function($scope) {
$scope.password = '';
// (?=(.*\d){2}) --> atleast 2 digits
// (?=(.*[a-z]){2}) --> atleast 2 lower case chars
// (?=(.*[A-Z]){2}) --> atleast 2 upper case chars
// (?=(.*[!@#$%]){2}) --> atleast 2 special chars, can be any one of !, @, #, $, %
$scope.pattern = /(?=(.*\d){2})(?=(.*[a-z]){2})(?=(.*[A-Z]){2})(?=(.*[!@#$%]){2})/;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyController">
<form name="myForm">
<label>Enter password: </label>
<input type="password" name="password" ng-model="password" ng-pattern="pattern">
<span style="color:red" class="error" ng-show="myForm.password.$error.pattern">Password is not valid, doesn't match the provided pattern.</span>
</form>
</div>
这篇关于密码的正则表达式,包含至少2个大写字母,2个小写字母,2个符号和2个任意顺序的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文