当我在RegEx()中使用它时,这在JavaScript密码验证中不起作用:
(?=(.*\\d){2,})(?=(.*[A-Z]){2,})(?=(.*[a-z]){2,})(?=(.*[!@#$%^&*?]){2,})(?!.*[\\s])^.*
答案 0 :(得分:1)
你走了:
我使用的正则表达式是:
1)(?=(。 \ d){2}) - >至少2位数
2)(?=(。 [a-z]){2}) - >至少2个小写字母
3)(?=(。 [A-Z]){2}) - >至少2个小写字母
4)(?=(。 [!@#$%]){2}) - >至少2个特殊字符,可以是!,@,#,$,%
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 lower 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>