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

Samaksh Wani
Giga Sage
Giga Sage

var date = g_form.getValue('date_field');

var regexp = /^(19|20)\d\d[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/;//regular expression for yyyy-mm-dd

 

if(!regex.test(date)){

g_form.clearValue('date_field');

}

Samaksh Wani
Giga Sage
Giga Sage

Hello @swaroop 

 

Plz mark my response as Accept which has included the script, It will help the future readers to get good understanding.

 

You can mark multiple solution as per community new rules.