如何验证DateTime格式? [英] How to validate DateTime format?

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

问题描述

我想,让用户输入一个日期时间格式,但我需要验证它来检查它是否是可以接受的。用户可以输入YYYY-MM-DD,这将是罚款,但他们也可以进入MM / YYYYMM / DDD或任何其他组合。有没有一种方法来验证这一点?

I am suppose to let the user enter a DateTime format, but I need to validate it to check if it is acceptable. The user might enter "yyyy-MM-dd" and it would be fine, but they can also enter "MM/yyyyMM/ddd" or any other combination. Is there a way to validate this?

推荐答案

我不知道任何方式来实际验证他们因为有时进入格式要有意包括翻译成任何字符。您可能需要考虑的一件事是通过展示他们的东西进入的格式转换成一个预览,允许用户自我验证。

I don't know of any way to actually validate the format they enter since sometimes you want to intentionally include characters that translate into anything. One thing you might consider is allowing the user to self validate by showing a preview of what their entered format translates into.

这篇关于如何验证DateTime格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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