Validacion de un formulario Email
Posted by : ohkMalganis
on 10:45:00 a. m.
Por: el-brujo
Fuente Original: Aqui
Validar e-mail:
Código
function verify_email($email){
if(!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)){
return false;
} else {
return $email;
}
}
Código
function EmailValidation($email){
$email = htmlspecialchars(stripslashes(strip_tags($email))); //parse unnecessary characters to prevent exploits
if ( eregi ( '[a-z||0-9]@[a-z||0-9].[a-z]', $email ) )
{ //checks to make sure the email address is in a valid format
$domain = explode( "@", $email ); //get the domain name
if ( @fsockopen ($domain[1],80,$errno,$errstr,3))
{
//if the connection can be established, the email address is probably valid
return true;
} else
{
return false; //if a connection cannot be established return false
}
return false; //if email address is an invalid format return false
}
}
Código
function validar_email($email) {list($local, $domain) = explode("@", $email);
$pattern_local = '^([0-9a-z]*([-|_]?[0-9a-z]+)*)(([-|_]?)\.([-|_]?)[0-9a-z]*([-|_]?[0-9a-z]+)+)*([-|_]?)$';
$pattern_domain = '^([0-9a-z]+([-]?[0-9a-z]+)*)(([-]?)\.([-]?)[0-9a-z]*([-]?[0-9a-z]+)+)*\.[a-z]{2,4}$';
$match_local = eregi($pattern_local, $local);
$match_domain = eregi($pattern_domain, $domain);
if ($match_local && $match_domain) {
return 1;
} else {
return 0;
}
}
En PHP 5:
Se añade la funcionalidad de filter_var
Código
if(filter_var("prueba@dominio.com", FILTER_VALIDATE_EMAIL)){echo "Ok";
} else {
echo "Error";
}
Usando filter _var y comprobando que tenga un punto el dominio con una expresión regular:
Código
function validateEmailAddress($email) {return filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match('/@.+\./', $email);
}
Ejemplo Wordpress (usando expresiones regulares)
Código
function is_email($email) {if( strlen( $email ) < 3 ){
return false;
}
if( strpos( $email, '@', 1 ) === false ){
return false;
}
list( $local, $domain ) = explode( '@', $Valor, 2 );
if( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ){
return false;
}
if( preg_match( '/\.{2,}/', $domain ) ){
return false;
}
if( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ){
return false;
}
$subs = explode( '.', $domain );
if( 2 > count( $subs ) ){
return false;
}
foreach ( $subs as $sub ) {
if( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ){
return false;
}
if( !preg_match('/^[a-z0-9-]+$/i', $sub ) ){
return false;
}
}
return true;
}
Verificar e-mail mirando registro MX si es válido, útil para separar nombre y dominio de un e-mail
Código
function verify_email_dns($email){// This will split the email into its front
// and back (the domain) portions
list($name, $domain) = explode('@',$email);
if(!checkdnsrr($domain,'MX')){
// No MX record found
return false;
} else {
// MX record found, return email
return $email;
}
}
Código
$string = 'some_name@somedomain.com';$res = explode('@', $string);
// array
echo $res[0];
$name = $res[0];
echo $name;
substr
Código
$mail = "some_name@somedomain.com";echo substr($mail, 0, strpos($mail, '@') );
explode
Código
list($name, $domain) = explode('@', $mail);echo $name;
Etiquetas:
Desarrollo Web,
haxs,
Php
Suscribirse a:
Enviar comentarios (Atom)
0 comentarios:
Publicar un comentario