07/04/2012, 23:38
|
| | | Fecha de Ingreso: junio-2006
Mensajes: 124
Antigüedad: 18 años, 5 meses Puntos: 0 | |
Respuesta: Como valida numero de telefono Cita:
Iniciado por Chico3001 Alli esta... Código PHP: <?php
require ("ClassMathGuard.php");
function validar_tel($tel) {
$tel = preg_replace("/[^0-9]/","",$tel);
if ((strlen($tel) == 11) || (strlen($tel) == 10))
return TRUE;
else
return FALSE;
}
if($_POST)
{
$javascript_enabled = trim($_POST['browser_check']);
$department = trim($_POST['dept']);
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phno = trim($_POST['phno']);
$subject = trim($_POST['subject']);
$msg = trim($_POST['msg']);
$selfcopy = trim($_POST['selfcopy']);
//mail settings
$sales_address = "[email protected]";
$support_address = "[email protected]";
$billing_address = "[email protected]";
$headers = "From: ".$email;
$message = "Contact name: $name\nContact Email: $email\nContact Phone: $phno\n\nMessage: $msg";
if (MathGuard :: checkResult($_POST['mathguard_answer'], $_POST['mathguard_code'])) {
if ( $department == "sales") $to = $sales_address;
elseif ( $department == "support") $to = $support_address;
elseif ( $department == "billing") $to = $billing_address;
if ( $name == "" )
{
$result = "Name field is required";
}
elseif (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/", $email))
{
$result = "Enter a valid email address";
}
elseif(!validar_tel($phno)) //check for a pattern of 91-0123456789
{
$result = "Enter a valid phone number";
}
elseif ( $subject == "" )
{
$result = "Subject is required";
}
elseif ( strlen($msg) < 10 )
{
$result = "Write more than 10 characters";
}
else
{
mail($to, $subject, $message, $headers);
if( $selfcopy == "yes" )
mail($email, $subject, $message, $headers);
$result = "Your mail has been sent succesfully!";
}
}
else $result = "Bad Answer, Please try again!";
if($javascript_enabled == "true") {
echo $result;
die();
}
}
?> GRACIAS Chico3001 FUNCIONO DE MARAVILLAS!
Saludos! |