I have a password field and I need to check using javascript if it has the following characters:
! @ # $ % ^ & *
I tried to do it like this, and it's working as expected:
function ValidarPass() { var Contrasena = document.getElementById('Clave').value; if(Contrasena!='' && (Contrasena.indexOf('!')>-1|| Contrasena.indexOf('@')>-1|| Contrasena.indexOf('#')>-1|| Contrasena.indexOf('$')>-1|| Contrasena.indexOf('%')>-1|| Contrasena.indexOf('^')>-1|| Contrasena.indexOf('&')>-1|| Contrasena.indexOf('*')>-1)) { alert("Exito!"); } else { alert("Error!"); } } Is there an easier/efficient way to do this?