<label for="age">Age:</label>
    <input type="date" id="age" name="age" />
    <p>you should select one age  09/04/1984.</p>
$age = $_POST["age"];
if(!preg_match('/[0-9]{4}-[1-12]{1,2}-[1-31]{1,2}/',$age)){
 echo "you should select one age 09/04/1984.";
}

there is always echo "you should select one age 09/04/1984.";

    [0-9] means "every character from 0 to 9", so it means the same thing as [0123456789].
    [1-12] means "any character from 1 to 1 or maybe 2", so it means the same thing as [12].
    [1-31] means "any character from 1 to 3 or maybe 1", so it means the same thing as [123].

      I don't know regular expressions

        PHP already has functions for parsing and checking the validity of dates. You don't want to see the regular expression you'd need to do the job.

          
          $onlynumberssage = preg_replace("/(19[0-9][0-9]|20[0-9][0-9]){4}-[01-12]{2}-[01-31]{2}/","", $age);
          if(date_parse_from_format("Y-n-j",$onlynumberssage )){
              mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
              $link = mysqli_connect("localhost", "root", "P-11fl32fg14", "check-in");
              $query = "INSERT INTO check-in (age) VALUES ('$onlynumbersage ')";
              echo $query;
              mysqli_query($link, $query);
          
              mysqli_close($link);
          }
          elseif(!empty($onlynumberssage )){
              echo "you should enter one age 09-04-1984.";
          }

          I must use for the variable $age before
          htmlentities($age);
          addslashes($age);
          $onlynumbers = preg_replace("/\D/","", $age);
          $age_sanitize_int= filter_var($age,FILTER_SANITIZE_INT);

            Personally, I'd take regular expressions completely out of the process. First, I'd be sure to use a date-type input element in the HTML form. Then in the PHP, I'd just see if it "works", something like:

            $parts = explode('-', $_POST["age"]);
            if(count($parts) == 3 && checkdate($parts[1], $parts[2], $parts[0])) {
                // we are good to go
            } else {
                // invalid date
            }
            

            /(19[0-9][0-9]|20[0-9][0-9]){4}-[01-12]{2}-[01-31]{2}/
            So Bobby1907209920731999-22-00');truncate table check-in-- would be valid, but 1981-04-09 would not.

            Can I just point out that "age" is a funny name for a date?

              Write a Reply...