1

I need to check that the user has given a valid date in a text box. For example if user enters 2014-02-29 it should throw an error saying it is not a valid date. I can use Date datatype but my requirement is that i need to use text box because in some condition it need to get data value and in some condition it need to get string value.

Thanks IRaj

1 Answer 1

3

There was another user looking to do the same thing on stackoverflow. He ended up solving his own question:

So I used a regex to validate the format of the date being entered to ensure it is in yyyy-MM-dd format.

The I used Date.valueOf This built in method always takes a date in the form of yyyy-MM-dd. It throws an exception if that has a bad value like 9999-99-99 etc....I display the exception's message to the user using e.getMessage() to complete my validation of the date fields.

1
  • Hi Jenny, Its working for me but Im not getting any error. Im getting next valid date. With some if conditions i am able to get my answer. Thanks for the help.
    – Tamil
    Commented Sep 29, 2014 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .