Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
- <title>Validator</title>
- <style type="text/css">
- body{
- background-color: #FBB917;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <form action="#" method="POST">
- <div class="row">
- <div class="offset-md-4 col-md-4">
- <label for="date" class="form-label">Date</label>
- <input type="text" name="date" id="date" class="form-control">
- </div>
- </div>
- <div class="row">
- <div class="offset-md-4 col-md-4">
- <label for="time" class="form-label">Time</label>
- <input type="text" name="time" id="time" class="form-control">
- </div>
- </div>
- <div class="row">
- <div class="offset-md-4 col-md-4">
- <input type="submit" name="validate" class="form-control">
- </div>
- </div>
- <div class="row">
- <div class="offset-md-4 col-md-4">
- <?php
- if (isset($_POST["validate"])){
- $date = $_POST["date"];
- $re = '/^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/m';
- preg_match_all($re, $date, $matches, PREG_SET_ORDER, 0);
- if (isset($matches[0][0])){
- echo "<h2>".$date." е валидна дата</h2>";
- } else {
- echo "<h2>Невалидна дата</h2>";
- }
- }
- ?>
- </div>
- </div>
- <div class="row">
- <div class="offset-md-4 col-md-4">
- <?php
- if (isset($_POST["validate"])){
- $time = $_POST["time"];
- $regexTime = "/^(([0-1][0-9])|(2[0-3]))(:[0-5][0-9]){2}$/";
- if (preg_match($regexTime, $time)){
- echo "<h2>".$time." е валидно време</h2>";
- } else {
- echo "<h2>Невалидно време</h2>";
- }
- }
- ?>
- </div>
- </div>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement