【问题标题】:How to check date format in Spring WebFlow2如何在 Spring WebFlow2 中检查日期格式
【发布时间】:2012-09-05 00:08:47
【问题描述】:

如何在 Spring WebFlow2 中检查日期格式。

我正在尝试查找一些可与 Spring Webflow 一起使用的代码,以检查用户输入的日期是否有效。我认为这是一个简单的检查

【问题讨论】:

    标签: java spring spring-mvc spring-webflow


    【解决方案1】:

    在客户端使用 JavaScript 正则表达式,在服务器端使用 java.text.DateFormat

    DateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd");
    formatter.setLenient(false);
    String dateAsString = request.getParameter("date");
    Date date = formatter.parse(dateAsString); // throws an exception if the String is incorrectly formatted.
    

    【讨论】:

    • 是的,在您的 Controller、Action、Validator 或您在 SpringMVC 和 Spring WebFlow 下进行服务器端验证的任何方式中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 2018-07-03
    • 2010-10-25
    相关资源
    最近更新 更多