Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
usando la condición en el botón onclick de jquery

Estoy tratando de confirmar si la seguridad de la contraseña es segura o débil y si la contraseña es segura y cuando la envíe debería tener un mensaje de alerta como "Tiene una contraseña segura" y cuando es débil "Contraseña no válida"

Esto es lo que soy ahora.

 function checkPasswordStrength() { var passwordStrength = false; var number = /([0-9])/; var alphabets = /([a-zA-Z])/; var special_characters = /([~,!,@,#,$,%,^,&,*,-,_,+,=,?,>,<])/; if ($('#password').val().length < 8) { $('#password-strength-status').removeClass(); $('#password-strength-status').addClass('weak-password'); $('#password-strength-status').html("Weak (should be atleast 8 characters.)"); } else { if ($('#password').val().match(number) && $('#password').val().match(alphabets) && $('#password').val().match(special_characters)) { $('#password-strength-status').removeClass(); $('#password-strength-status').addClass('strong-password'); $('#password-strength-status').html("Strong"); return passwordStrength = true; } else { $('#password-strength-status').removeClass(); $('#password-strength-status').addClass('medium-password'); $('#password-strength-status').html("Medium (should include alphabets, numbers and special characters.)"); } } } $('#btn-submit').click(function () { if (passwordStrength == false) { alert("INVALID PASSWORD"); } else { alert("You have Strong PASSWORD"); } </script>

es solo para fines educativos. Estoy comenzando con jquery.. gracias de antemano..

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Parece que el alcance de la variable es incorrecto. var passwordStrength debe colocarse fuera de la función checkPasswordStrength .

 var passwordStrength function checkPasswordStrength() { ....
over 4 years ago · Santiago Trujillo Report

0

Debe llamar a la función en lugar de simplemente verificar su variable. Así que mejor hazlo

 $('#btn-submit').click(function () { if (checkPasswordStrength() === false) {

en vez de

 $('#btn-submit').click(function () { if (passwordStrength == false) {

Luego, en lugar de return passwordStrength = true; debe hacer simplemente passwordStrength = true y agregar una return passwordStrength de retornoFuerza al final de su función para que devuelva falso o verdadero.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!