JavaScript - 验证日期 [英] JavaScript - Validate Date

查看:116
本文介绍了JavaScript - 验证日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML文本字段。我想通过JavaScript验证输入的值是MM / DD / YY或MM / D / YY或MM / DD / YYYY或MM / D / YYYY形式的有效日期。有没有这样的功能?



我认为有一些类似isNaN的东西,但我看不到任何东西。 JavaScript是否可以验证日期?

解决方案


验证日期?


否。


有没有这样的功能?


否。



您将需要编写自己的验证函数来解析日期格式(请注意正则表达式),然后确定它是否在您的特定标准中有效。


I have an HTML text field. I want to validate via JavaScript that the value entered is a valid date in the form of "MM/DD/YY" or "MM/D/YY" or "MM/DD/YYYY" or "MM/D/YYYY". Is there a function that does this?

I sort of assumed there was something like isNaN but I don't see anything. Is it true that JavaScript can't validate dates?

解决方案

Is it true that JavaScript can't validate dates?

No.

Is there a function that does this?

No.

You will need to write your own validation function to parse the date format (regex comes to mind) and then determine if it is valid within your specific criteria.

这篇关于JavaScript - 验证日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆