I want to validate password entered by user for following criteria :
Password should be at least 8 characters long and should contain one number,one character an
Just a couple notes
1) The above contains one redundant $
. It should be ng-pattern="/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/"
2) Don't remove leading ^
and trailing $
as it prevents from entering white spaces
3) If you want to define the pattern in controller then
$scope.passwordStrength = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/;
and
but never
$scope.passwordStrength = "/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/";
as the pattern is a RegExp object, not a string.
Hope this will help you save some time.