function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TamilTamil 

Date Validation

HI,

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
SarfarajSarfaraj
Create a date object using the field value. If it throws exception the date value is incorrect. Example,
try
{
    Date dt = Date.valueOf(userInput);
}
catch(Exception e)
{
     //Write exception handling code here. You may show the user some information about the wrong input
    //See documentation about pagemessage.
     return;
}


TamilTamil
Hi Akram,
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.
IRaj