Regd. Validation of Date format for a Path Param

205 views
Skip to first unread message

Thirumalarao Kankanala

unread,
Aug 5, 2014, 7:06:31 AM8/5/14
to dropwiz...@googlegroups.com

Hi All,

Greetings for the day J

 I wanted to use a regular expression to validate the input date format as “yyyy-mm-dd” which is a path parameter.

I tried as follows, but it is giving the Invalid syntax for the expression '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]' Exception.

       @GET

       @Path("/{estdDate: [0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]}")

       public EstdDateResponse SendDateResponse(

                     @PathParam("estdDate") String estdDate)

                     throws DatatypeConfigurationException {

}

 I don't want to pass format to validate in resource request.

Please let me know how to use regular expressions to validate the date format as defined.

Jochen Schalanda

unread,
Aug 5, 2014, 7:18:28 AM8/5/14
to dropwiz...@googlegroups.com
Hi,

you might want to take a look at Dropwizard's DateTimeParam [1, 2]. It
should be reasonably straightforward to create a similar class for
LocalDate [3] (pull requests welcome).


[1]:
http://dropwizard.io/0.7.1/dropwizard-jersey/apidocs/io/dropwizard/jersey/params/DateTimeParam.html
[2]:
https://github.com/dropwizard/dropwizard/blob/v0.7.1/dropwizard-jersey/src/main/java/io/dropwizard/jersey/params/DateTimeParam.java
[3]: http://www.joda.org/joda-time/apidocs/org/joda/time/LocalDate.html


Cheers,
Jochen


On 05.08.2014 13:06, Thirumalarao Kankanala wrote:
> Hi All,
>
> Greetings for the day J
>
> I wanted to use a regular expression to validate the input date format
> as “yyyy-mm-dd” which is a path parameter.
>
> I tried as follows, but it is giving the Invalid syntax for the
> expression '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]' Exception.
>
> @GET
>
> @Path("/{estdDate:
> [0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]}")
>
> *public* EstdDateResponse SendDateResponse(
>
> @PathParam("estdDate") String estdDate)
>
> *throws* DatatypeConfigurationException {
>
> }
>
> I don't want to pass format to validate in resource request.
>
> Please let me know how to use regular expressions to validate the date
> format as defined.
>
> --
> You received this message because you are subscribed to the Google
> Groups "dropwizard-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dropwizard-de...@googlegroups.com
> <mailto:dropwizard-de...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages