Speak ae, you can use regex to check the fields.
Below is a brief explanation.
(?=.*[a-z]) A string deve conter uma letra minuscula
(?=.*[A-Z]) A string deve conter uma letra maiuscula
(?=.*[0-9]) A string deve conter um numero de 0 a 9
(?=.[!@#\$%\^&]) A string deve conter uma caractere especial
(?=.{8,}) A string deve conter 8 ou mais caracteres.
The code below is not mine(Original:
https://www.thepolyglotdeveloper.com/2015/05/use-regex-to-test-password-strength-in-javascript/)
It creates an "Analyze" function that is called in ng-change to validate the previously reported conditions.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script>
var myApp = angular.module("myapp", []);
myApp.controller("PasswordController", function($scope) {
var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})");
var mediumRegex = new RegExp("^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})");
$scope.passwordStrength = {
"float": "left",
"width": "100px",
"height": "25px",
"margin-left": "5px"
};
$scope.analyze = function(value) {
if(strongRegex.test(value)) {
$scope.passwordStrength["background-color"] = "green";
} else if(mediumRegex.test(value)) {
$scope.passwordStrength["background-color"] = "orange";
} else {
$scope.passwordStrength["background-color"] = "red";
}
};
});
</script>
</head>
<body ng-app="myapp">
<div ng-controller="PasswordController">
<div style="float: left; width: 100px">
<input type="text" ng-model="password" ng-change="analyze(password)" style="width: 100px; height: 25px" />
</div>
<div ng-style="passwordStrength"></div>
</div>
</body>
</html>
Are you using reactive Forms? You can post your code.
– Eduardo Vargas
@Eduardovargas, I put the code, but I’m not using any method to get these values I need because I don’t know exactly how to get it, but the logic is equal to this "length" that I’m taking through ngModel, so I don’t use reactive forms here.
– Henrique Mendes Silveira Rodri