- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:20 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:34 AM - edited 07-26-2023 07:46 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:52 AM
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');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2023 07:57 AM
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.