简体   繁体   English

Javascript正则表达式格式

[英]Javascript Regex format

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? 什么是正则表达式和/或jquery / javascript函数,我将用它来确保此输入匹配此?

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}/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM