Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 233
BlissC Avatar asked Dec 02 '22 06:12

BlissC


1 Answers

That would be sufficient for simple check;

    $input = (int)$input;
    if($input>1000 && $input<2100)
    {
      //valid
    }
like image 183
mth Avatar answered Dec 04 '22 01:12

mth