Search code examples
phpvalidationformsdate

PHP form validation for year


I'm using PHP to validate form input before the form data's submitted to a MySQL database.

What would be the best way to validate a form input for the year only? I have a form input where users should input a date, in the form of a year only. Obviously I can check that the input's numeric and has only 4 characters, but what would be the best way to ensure that the number inputted is a sensible number for a date?


Solution

  • That would be sufficient for simple check;

        $input = (int)$input;
        if($input>1000 && $input<2100)
        {
          //valid
        }