Valida Email en javascript
Por MigueliTUX Aug.25, 2009, categoría HTML, JavaScript
Código JavaScript:
function validarEmail(valor) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){ alert("La dirección de email " + valor + " es correcta.") return (true) } else { alert("La dirección de email es incorrecta."); return (false); } }
Código HTML:
<input type="text" name="email" size="50">
<input type="button" value="Validar e-mail" onClick="validarEmail(this.form.email.value);">
August 25th, 2009 on 2:50 pm
el llamado podria ser
onClick=”validarEmail(this.form.email);”
y en la funcion podrias dar el focus a la casilla
function validarEmail(obj) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value)){
alert(”La dirección de email ” + obj.value + ” es correcta.”)
return (true)
} else {
alert(”La dirección de email es incorrecta.”);
obj.focus();
return (false);
}
}
pero esta realmente buena la validacion, yo nunca me acuerdo de esto, y me pongo a buscar como loko.
–
Atte.
victor Hugo Saavedra
http://vhspiceros.blogspot.com
August 25th, 2009 on 3:04 pm
Gracias Victor por el aporte…
May 29th, 2010 on 1:53 pm
[...] Email en javascript http://www.tips.cl/archives/465 #TipsCL [...]
June 5th, 2010 on 1:50 pm
[...] Email en javascript http://www.tips.cl/archives/465 #TipsCL [...]
June 19th, 2010 on 1:47 pm
[...] Email en javascript http://www.tips.cl/archives/465 #TipsCL [...]