admin管理员组文章数量:1024592
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])^.*
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])^.*
Share
Improve this question
edited Feb 25, 2017 at 23:32
Peter Mortensen
31.6k22 gold badges110 silver badges133 bronze badges
asked Feb 25, 2017 at 7:37
SamSam
331 silver badge2 bronze badges
2
- Maybe better don't use regex for this purpose? I would write it on JS. – artamonovdev Commented Feb 25, 2017 at 8:24
- it is not working even in ng-pattern @artamonovdev – Sam Commented Feb 25, 2017 at 8:29
2 Answers
Reset to default 6Here you go:
The regex that I've used is:
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./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>
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./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>
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])^.*
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])^.*
Share
Improve this question
edited Feb 25, 2017 at 23:32
Peter Mortensen
31.6k22 gold badges110 silver badges133 bronze badges
asked Feb 25, 2017 at 7:37
SamSam
331 silver badge2 bronze badges
2
- Maybe better don't use regex for this purpose? I would write it on JS. – artamonovdev Commented Feb 25, 2017 at 8:24
- it is not working even in ng-pattern @artamonovdev – Sam Commented Feb 25, 2017 at 8:29
2 Answers
Reset to default 6Here you go:
The regex that I've used is:
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./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>
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./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>
本文标签:
版权声明:本文标题:javascript - Regular expression for a password containing at least 2 uppercase letters, 2 lowercase letters, 2 symbols, and 2 nu 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745609850a2158940.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论