Validate E-mail and URL in PHP

Total Post:113

Points:791
PHP 
PHP
 341  View(s)
Ratings:
Rate this:

Validate E-mail and URL in php ?

  1. Post:140

    Points:984
    Re: Validate E-mail and URL in PHP

    Validate E-mail and URL in PHP :

    Validate Name: 

    $name = test_input($_POST["name"]); 
    if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
      $nameErr = "Only letters and white space allowed";
    }

    Validate E-mail: 

    $email = test_input($_POST["email"]); 
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $emailErr = "Invalid email format";
    }

    Validate URL: 

    $website = test_input($_POST["website"]); 
    if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/
    %=~_|]/i",$website)) {
      $websiteErr = "Invalid URL";
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!