If Date entered manually in date field is not in a format, the field should auto clear.

swaroop
Kilo Sage

Hello All,

I am trying to write a On Change script to validate if Date entered manually in a Date field is in Good Format or not. If it is not in 'YYYY-MM-DD' Format, field should auto clear. 

Can anyone suggest me any script for achieving this.

 

Thanks & Regards,

S.Swaroop.

1 ACCEPTED SOLUTION

Zach Koch
Giga Sage
Giga Sage

You can use regex to look for that format, then if it doesn't match clear the field and give an error message stating the format needed. Use the link below to help with the regex pattern needed.

Regex website 

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

View solution in original post

6 REPLIES 6

Zach Koch
Giga Sage
Giga Sage

You can use regex to look for that format, then if it doesn't match clear the field and give an error message stating the format needed. Use the link below to help with the regex pattern needed.

Regex website 

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Hello Zach,

 

It worked. Thank You 🙂

 

Thanks & Regards,

S.Swaroop.

Awesome! Glad I could help!

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

SP22
Mega Sage
Mega Sage
function onChange(control, oldValue, newValue, isLoading) {
       if (isLoading || newValue == oldValue) {
                   return;
       }
       if (getDateFromFormat(newValue, 'YYYY-MM-DD') == 0) {
                   g_form.hideErrorBox('pstart_date'); //user your field name
                   g_form.showErrorBox('pstart_date', 'Date is invalid');
       }
       else {
                   g_form.clearValue('pstart_date');
       }
}