Advertisement
vencinachev

Time validation

Mar 10th, 2021
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <title>Валидатор за час</title>
  5. </head>
  6. <body bgcolor="#99ffcc">
  7.    <h2>Валидатор на час</h1>
  8.    <form action="#" method="post">
  9.     <label for="time">Час: </label>
  10.     <input type="text" name="time">
  11.     <input type="submit" name="validate" value="Валидирай">
  12.    </form>
  13.    <?php
  14.      if (isset($_POST["validate"])){
  15.          $time = $_POST["time"];
  16.          $regex = "/^(([0-1][0-9])|(2[0-3]))(:[0-5][0-9]){2}$/";
  17.          if (preg_match($regex, $time)){
  18.              echo "<p>".$time." is valid!</p>";
  19.          } else {
  20.              echo "<p>NOT VALID</p>";
  21.          }
  22.      }
  23.          
  24.    ?>
  25. </body>
  26. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement