How to check the data format in PHP

前端 未结 6 1794
忘掉有多难
忘掉有多难 2021-01-21 04:07

I am trying to check a date format to see if I can check the data variable has certain format like MM-DD-YYYY. if not, then exit(). I am not sure how to check the format and wou

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-21 04:37

    you can use regular expressions

    if(preg_match("/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/"))
    {
        do something
    } 
    

提交回复
热议问题