简体   繁体   English

如何在没有JavaScript的情况下以jsp格式在客户端验证日期?

[英]How to validate date on the client side in jsp form without javascript?

The date picker doesn't show up even though i use 即使使用,日期选择器也不会显示

  <input type="date" name="dob" required>  

Additional information that might help you help me : It is in a JSP file I'm using tomcat v7.0 I need to validate the date without using JavaScript? 可能对您有帮助的附加信息:它在JSP文件中,我正在使用tomcat v7.0,我需要在不使用JavaScript的情况下验证日期吗?

I tried using text for input and setting a specified format but then how can I add range there? 我尝试使用文本进行输入并设置指定的格式,但是如何在其中添加范围? (min max and dynamic for February issues?) (2月问题的最低最高和最高动态水平?)

Can this issue be addressed by using combobox? 通过使用组合框可以解决此问题吗? How can I change value options of one combo box depending on the other? 如何根据另一个组合框更改值选项? (Date options dependent on month and/or year) (日期选项取决于月份和/或年份)

Any help is highly appreciated. 非常感谢您的帮助。

PS Since it is a part of a registration form, I have been advised against using JavaScript validation (as it can be disabled) PS:由于它是注册表格的一部分,因此建议我不要使用JavaScript验证(因为可以禁用它)

Edit : I guess I'll go with a regular expression. 编辑:我想我会去一个正则表达式。 I found one here, the second answer to this question : Regular Expression to match valid dates 我在这里找到了这个问题的第二个答案: 正则表达式以匹配有效日期

The date picker doesn't show up 日期选择器未显示

It does when I test it. 当我测试它的时候。 Perhaps you are using a browser which does not support it . 也许您使用的浏览器不支持它

I tried using text for input and setting a specified format but then how can I add range there? 我尝试使用文本进行输入并设置指定的格式,但是如何在其中添加范围?

If by "format" you mean a pattern , then you would need a complex regular expression that had multiple parts. 如果用“格式”表示pattern ,那么您将需要一个包含多个部分的复杂正则表达式。

eg 0 followed by 1-9, or 1 followed by 0-9, or 2 followed by 0-8 followed by / followed by 02 followed by (leap year logic) . 例如0后跟1-9,或1后跟0-9,或2后跟0-8,再跟/后跟02,再跟(le年逻辑)

It wouldn't be short or pretty. 它不会短或漂亮。

Regular expressions do not lend themselves to describing the format of dates. 正则表达式不适合描述日期格式。

That said, see this question . 也就是说, 请参阅此问题

Can this issue be addressed by using combobox? 通过使用组合框可以解决此问题吗?

You can't have a combobox in HTML without using JavaScript, which you ruled out. 如果不使用JavaScript,就无法使用HTML组合框,但您不能使用JavaScript。

If you mean "a collection of select elements" then that would be "dropdown menus" not "a combobox". 如果您的意思是“选择元素的集合”,那么它将是“下拉菜单”而不是“组合框”。

You could use those, but there's no good way to stop people entering dates like the 31st of February. 您可以使用这些日期,但是没有很好的方法来阻止人们输入2月31日这样的日期。

How can I change value options of one combo box depending on the other? 如何根据另一个组合框更改值选项?

Only with JavaScript, which you ruled out. 仅适用于您已排除的JavaScript。


Since it is a part of a registration form, I have been advised against using JavaScript validation (as it can be disabled) 由于它是注册表格的一部分,因此建议我不要使用JavaScript验证(因为可以禁用它)

You shouldn't depend on JavaScript for input validation because it can be bypassed… but that is true of any client-side input validation you might implement. 您不应该依赖 JavaScript进行输入验证,因为可以绕过它……但是对于您可能实现的任何客户端输入验证都是如此。

Client-side input checking is useful because it can give users rapid feedback if they make a mistake and enter data which doesn't make sense. 客户端输入检查很有用,因为它可以给用户快速的反馈,如果他们犯了错误并且输入了没有意义的数据。

You need to accompany it with server-side input checking in order to prevent bad data being inserted into your system deliberately. 您需要将其与服务器端输入检查一起进行,以防止将不良数据故意插入到您的系统中。

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

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