arif11015

class-3-part-20

Aug 12th, 2021 (edited)
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Filter Variable
  4.  * https://www.w3schools.com/php/php_ref_filter.asp
  5.  */
  6.  
  7. $email = "xossarif@gmail.com";
  8.  
  9. if (filter_var($email, FILTER_VALIDATE_EMAIL)){
  10.     //echo "This is a valid email";
  11. }else{
  12.    // echo "This is not valid Email address";
  13. }
  14.  
  15. echo "<br/>";
  16. $int = 213243.23234;
  17.  
  18. if (filter_var($int, FILTER_VALIDATE_INT)){
  19.     //echo "this is Int";
  20. }else{
  21.     //echo "this is not";
  22. }
  23. echo "<br/>";
  24.  
  25. if (isset($_REQUEST['submit'])){
  26.     $email = $_REQUEST['email'];
  27.     if (isset($email)){
  28.         $email_data_sanitize = filter_var($email, FILTER_SANITIZE_EMAIL);
  29.         $email_data_validate = filter_var($email_data_sanitize, FILTER_VALIDATE_EMAIL);
  30.  
  31.         if ($email_data_validate && $email_data_validate){
  32.             echo "$email is correct";
  33.         }else{
  34.             $error =  "$email is Incorrect";
  35.         }
  36.  
  37.     }
  38. }
  39.  
  40. ?>
  41.  
  42. <!doctype html>
  43. <html lang="en">
  44. <head>
  45.     <meta charset="UTF-8">
  46.     <meta name="viewport"
  47.           content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  48.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  49.     <title>Document</title>
  50. </head>
  51. <body>
  52. <form action="" method="POST">
  53.     <input type="text" placeholder="Email" name="email"> <br/>
  54.     <input type="submit" name="submit" value="submit">
  55. </form>
  56. <p><?php if (isset($error)){
  57.         echo $error;
  58.     } ?></p>
  59.  
  60. </body>
  61. </html>
  62.  
Add Comment
Please, Sign In to add comment