I have a code that does a checking of the password and if it is short, print the corresponding.
My problem is that I have the variable return and I need this to print a text wrapped in <p>...</p>
, but I do not know how to do it. Here I leave the code.
$('#password').keyup(function () {
$('#result').html(checkStrength($('#password').val()))
})
function checkStrength(password) {
var strength = 0
if (password.length < 6) {
$('#result').removeClass()
$('#result').css("background-color", "red"),
return 'Too short'
}
if (password.length > 7) strength += 1
if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) strength += 1
if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) strength += 1
if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1
if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/)) strength += 1
if (strength < 2) {
$('#result').removeClass(),
$('#result').css("background-color" , "orange")
return 'Weak'
} else if (strength == 2) {
$('#result').removeClass()
$('#result').css("background-color", "green")
return 'Good'
} else {
$('#result').removeClass()
$('#result').css("background-color", "var(--jobcafe-grün)")
return 'Strong'
}
}
I hope someone can help me. Greetings