HTML5 Date Validation

后端 未结 4 1232
难免孤独
难免孤独 2021-01-19 03:07

I\'m looking to implement validation for a mobile site, where I have two input fields and I would like the first to validate the value is no later than todays date, and the

4条回答
  •  余生分开走
    2021-01-19 04:12

    You can use a Regex pattern like this /([0-9]{2})/([0-9]{2})/([0-9]{4})/, that is, two decimal digits, a slash, two more decimal digits, a slash and four decimal digits, everything grouped separately (group 1 = day, group 2 = month, group 3 = year). You would test for this pattern in a event, (I would suggest onchange, since you mentioned mobile) and also check if the numbers are within a valid range (e.g. day < 32, month < 13, year < currentYear-1).

提交回复
热议问题