当输入的日期为invalid-jquery时引发异常 [英] Raise an exception when entered date is invalid-jquery

查看:56
本文介绍了当输入的日期为invalid-jquery时引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在jquery中输入的日期无效,我如何编写try和catch块来引发异常。



我尝试过:



如果您可以尝试回答这个问题,那将是一个很大的帮助。

How do i write a try and catch block to raise an exception when the entered date is invalid in jquery.

What I have tried:

It will be a big help if you can try and answer this question.

推荐答案

您可以使用 Moment.js [ ^ ]。它有 .isValid()来检查日期是否有效。



例如

You can make use of Moment.js[^]. It has .isValid() to check if the date is valid or not.

e.g.
moment("12/12/2016", "MM/DD/YYYY").isValid();//true
moment("13/12/2016", "MM/DD/YYYY").isValid();//false



除此之外,请查看: jquery - JavaScript检测有效日期 - 堆栈溢出 [ ^ ]


这篇关于当输入的日期为invalid-jquery时引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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