NetLizard
PHP - Validate E-mail
Bu orqali formdagi email togri yoki notogriligini aniqlaymiz.
  1. $email = test_input($_POST["email"]);
  2. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  3.   $emailErr = "Email xato yozildi";
  4. }

*- bu yerda filter_var() bu belgilangan togri emailga ruhsat beradi.
PHP - Validate URL
Bu sayt manzili togriligini aniqlaydi.
  1. $website = test_input($_POST["website"]);
  2. if (!preg_match("/\b(??:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
  3.   $websiteErr = "Invalid URL";
  4. }

Yuqoridagi barchasini qoshib tayyorlangan script:
  1. <?php
  2. // massiv
  3. $nameErr = $emailErr = $genderErr = $websiteErr = "";
  4. $name = $email = $gender = $comment = $website = "";
  5.  
  6. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  7.   if (empty($_POST["name"])) {
  8.     $nameErr = "Nomini yozing";
  9.   } else {
  10.     $name = test_input($_POST["name"]);
  11.     // nomni tekshirish
  12.     if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  13.       $nameErr = "Faqat harf va belgilangan simvollar";
  14.     }
  15.   }
  16.  
  17.   if (empty($_POST["email"])) {
  18.     $emailErr = "Email yozish kerak";
  19.   } else {
  20.     $email = test_input($_POST["email"]);
  21.     // email togri formatdaligini tekshiramiz
  22.     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  23.       $emailErr = "Email xato";
  24.     }
  25.   }
  26.  
  27.   if (empty($_POST["website"])) {
  28.     $website = "";
  29.   } else {
  30.     $website = test_input($_POST["website"]);
  31.     // URLni tekshirish
  32.     if (!preg_match("/\b(??:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
  33.       $websiteErr = "URL notogri";
  34.     }
  35.   }
  36.  
  37.   if (empty($_POST["comment"])) {
  38.     $comment = "";
  39.   } else {
  40.     $comment = test_input($_POST["comment"]);
  41.   }
  42.  
  43.   if (empty($_POST["gender"])) {
  44.     $genderErr = "Jins tanlang";
  45.   } else {
  46.     $gender = test_input($_POST["gender"]);
  47.   }
  48. }
  49. ?>