Foros del Web » Programando para Internet » Javascript »

Validar Mail

Estas en el tema de Validar Mail en el foro de Javascript en Foros del Web. Hola a todos. Tengo la siguiente función la cual valida un mail con el siguiente formato: [email protected] <script language="JavaScript"> <!-- function validar(pass){ var pos1, pos2, ...
  #1 (permalink)  
Antiguo 12/10/2004, 09:36
Avatar de Cuezaltzin  
Fecha de Ingreso: diciembre-2003
Ubicación: Frente al Monitor
Mensajes: 252
Antigüedad: 20 años, 5 meses
Puntos: 0
Validar Mail

Hola a todos.

Tengo la siguiente función la cual valida un mail con el siguiente formato:
[email protected]

<script language="JavaScript">
<!--
function validar(pass){
var pos1, pos2, bOk = true;
var sDir = document.frm.txtEMail.value;
if (sDir == ""){
alert("DEBE INGRESAR EL MAIL");
document.frm.txtEMail.focus();
return false;
}

pos1 = sDir.indexOf('@', 0);
pos2 = sDir.indexOf('.', 0);

bOk = bOk && (pos1 > 0);
bOk = bOk && (pos2 != -1);

bOk = bOk && (pos1 < pos2 - 1);
bOk = bOk && (pos2 < sDir.length - 1);

if (!bOk){
alert("DIRECCION DE CORREO NO VALIDA");
document.frm.txtEMail.focus();

return false;
}

return true
}
-->
</script>

Como le puedo hacer para validar un mail que tenga el siguiente formato:
[email protected]

Gracias Por su ayuda.
__________________
Hasta la victoria Siempre.
  #2 (permalink)  
Antiguo 12/10/2004, 11:17
Avatar de xcorpion  
Fecha de Ingreso: octubre-2003
Ubicación: m é x i c o
Mensajes: 676
Antigüedad: 20 años, 6 meses
Puntos: 4
alli lo tienes, lo saque de esta pagina http://www.codelifter.com/main/javas...schecker1.html
y fue tan simple como buscar "javascript mail validator" en google.com, echale ganas

================================================== ==========
Script: Email Address Checker-Validator

Functions:

Checks name field to see if empty
Checks e-mail address, which must have:
- "@" symbol and no spaces
- one or more good characters before
and after "@"
- .xx country code or .com, .net,
.edu, .mil, .gov, .org at end
First (em) and second (emx) email addresses
must be equal and name field must have more
than one character to pass the script tests

Browsers: All 4.0 and later browsers

Author: etLux
================================================== ==========

Put the following form and script in the body of your page:

<font size="2" face="Arial" color="#FF0000">
<form name="TheForm">
<input type="text" name="nm" size="33"> Your Name
<br><br>
<input type="text" name="em" size="33"> E-mail address
<br>
<input type="text" name="emx" size="33"> Re-enter to confirm
<br><br>
<input type="button" value="Submit" name="SB" onClick="sendOff();">

<script language="JavaScript1.2">

// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header

var good;
function checkEmailAddress(field) {

// Note: The next expression must be all on one line...
// allow no spaces, linefeeds, or carriage returns!
var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.go v)|(\.org)|(\..{2,2}))$)\b/gi);

if (goodEmail){
good = true
} else {
alert('Please enter a valid e-mail address.')
field.focus()
field.select()
good = false
}
}

function sendOff(){
nmcheck = document.TheForm.nm.value
if (nmcheck.length <1) {
alert('Please enter your name.')
return
}
good = false
checkEmailAddress(document.TheForm.em)
if ((document.TheForm.em.value ==
document.TheForm.emx.value)&&(good)){
// This is where you put your action
// if name and email addresses are good.
// We show an alert box, here; but you can
// use a window.location= 'http://address'
// to call a subsequent html page,
// or a Perl script, etc.
alert("Name and email address fields verified good.")
}
if ((document.TheForm.em.value !=
document.TheForm.emx.value)&&(good)){
alert('Both e-mail address entries must match.')
}
}
</script>
</form>
</font>

================================================== ==========
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:17.