I want to check if the input matches this format:
format: "dd/MM/yyyy"
Of course they would have to me numbers. What is the regex expression, and/or jquery/javascript function that i'd use to make sure this input matches this?
This should do it:
/^[0123]?\d\/[01]?\d\/\d{2,}$/
Remember that only certain numbers are valid months and days.
Other approaches can be found at the Regular Expression Library .
尝试这个:
var matches = str.search(/^\d{2}\/\d{2}\/\d{4}$/) > -1;
如果您只是想检查格式,而不是它实际上是一个有效日期,则以下内容应该有效:
/\d{2}\/\d{2}\/\d{4}/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.