Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <form action="action.php" method="post">
  2. <p>Your name: <input type="text" name="name"/></p>
  3. <p>Your age: <input type="text" name="age" /></p>
  4. <p><input type="submit" /></p>
  5. </form>
  6. Hi <?php echo htmlspecialchars($_POST['name']); ?>.
  7. You are <?php echo (int)$_POST['age']; ?> years old.
  8. <form action="action.php" method="post">
  9. <p>Your Email: <input type="text" name="email"/></p>
  10. <p><input type="submit" /></p>
  11. </form>
  12. <?php
  13. $email = $_POST['email'];
  14. $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
  15. if (preg_match($regex, $email)) {
  16. echo $email . " is valid";
  17. } else {
  18. echo $email . " is invalid.";
  19. }
  20. ?>
  21. <br>
  22. <br>
  23.  
  24.  
  25. <?php
  26. $phone_numbers = array(
  27. '555-555-5555',
  28. '555 555 5555',
  29. '1(519) 555-4444',
  30. '1 (519) 555-4422',
  31. '1-555-555-5555',
  32. '1-(555)-555-25555',
  33. );
  34. $regex = "/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}[\s-]?\d{4}$/i";
  35. foreach( $phone_numbers as $number ) {
  36. echo $number . ': ' . ( preg_match( $regex, $number ) ? 'valid' : 'invalid' ) . '<br/>';
  37. }
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement