Validacion Avanzada de E-mail Código PHP:
<%
'Funcion que comprueba si un e-mail es valido. Devuelve:
' 0 -> si es nulo o esta vacio
' 1 -> Si el e-mail es incorrecto
' 2 -> Si el e-mail es valido
Function Validar_EMail(EMail)
Dim Con
If EMail = "" Then
Validar_EMail = 0
Exit Function
End If
EMail = LCase(EMail)
If (Left(EMail, 1) = "." Or Left(EMail, 1) = "@") Then
Validar_EMail = 1
Exit Function
End If
If (Right(EMail, 1) = "." Or Right(EMail, 1) = "_" Or _
Right(EMail, 1) = "@") Then
Validar_EMail = 1
Exit Function
End If
Con = 0
For i = 1 To Len(EMail)
If (Mid(EMail, i, 1)) = "@" Then
Con = Con + 1
End If
Next
If Con > 1 Or Con = 0 Then
Validar_EMail = 1
Exit Function
End If
Con = 0
For i = 1 To Len(EMail)
If (Mid(EMail, i, 1)) = "@" Then
For j = i To Len(EMail)
If (Mid(EMail, j, 1)) = "." Then
Con = Con + 1
End If
Next
End If
Next
If Con < 1 Then
Validar_EMail = 1
Exit Function
End If
Con = 0
For i = 1 To Len(EMail)
If (Mid(EMail, i, 1) = ".") Or (Mid(EMail, i, 1) = "@") Then
If (Mid(EMail, i + 1, 1) = ".") Or (Mid(EMail, i + 1, 1) = "@") Then
Validar_EMail = 1
Exit Function
End If
End If
Next
For i = 1 To Len(EMail)
If (Mid(EMail, i, 1) < "a" Or Mid(EMail, i, 1) > "z") And _
(Mid(EMail, i, 1) < "0" Or Mid(EMail, i, 1) > "9") And _
Mid(EMail, i, 1) <> "." And Mid(EMail, i, 1) <> "_" And _
Mid(EMail, i, 1) <> "@" Then
Validar_EMail = 1
Exit Function
End If
Next
Validar_EMail = 2
End Function
%>
formulario:
Código PHP:
<!-- #Include File="ValidarEmail.asp"-->
<%
if request.form("envio") = "envio" then
if Validar_EMail(Request.form("correo")) = 0 then response.write "Nulo o Vacio"
if Validar_EMail(Request.form("correo")) = 1 then response.write "Email inválido"
if Validar_EMail(Request.form("correo")) = 2 then response.write "Email válido"
end if
%>
<BR>
<FORM METHOD="post" ACTION="verificar.asp">
<INPUT NAME="correo">
<INPUT TYPE="Submit">
<INPUT TYPE="Hidden" NAME="envio" VALUE="envio">
</FORM>