Jump to content
  • 0

Only allow date inputs within a specific range of dates


cordova

Question

Hi,

I have a date field in my submission form and I want to prevent the user from selecting a date that is not within a specified range of dates. Like for example, I only want the user to input dates that are within 12/01/2022 to 12/12/2022. Any dates that are not within that period will not be allowed.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi,

 

You can do this with a bit of JavaScript code.

 

So on your submission form, paste this script:

<script>

document.addEventListener("BeforeFormSubmit", function(e){
var date = Date.parse(document.getElementById("InsertRecordDate").value);

if(date >= Date.parse('12/01/2022') && date <= Date.parse('12/12/2022'))
{
//
}else
{
e.preventDefault();
alert("Invalid date");
}

});

</script>

 

The user gets prevented from submitting if the date is not within the specified range.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...