Conditional Logic: Form validation on date box

I’m creating a credit card form and I want to put form validation on all the boxes so it can be used as normal. I’m stuck on the “Expiry Date” box which needs to show a value of XX/XX. I’ve got it set to look for 5 character value but I’d like to get it more specific. Anyone know how I can do that?

Hi!

This uses the length of the string as well as date functions to verify the date. It gives an error if the date is in the wrong format or if the month/date is in the past.

Here is a brief explanation of some of the elements:

This expression converts the month/year entered to a date representing the first of the month, and then converts it to milliseconds. The ‘01/20’ is placed between the first three and last two characters, so 05/19 becomes ‘05/01/2019’. If the conversion fails, it will be because the date is in an invalid format or is an invalid month/year, and the expression will instead return ‘NaN’ which is not numeric. For example, ‘13/20’ will be rejected as 13 isn’t a month,

[[ (This.text.substr(0,3) + '01/20' + This.text.substr(3,2)).valueOf() ]]

This expression gets a date representing the last day of the month prior to the current month and converts it to milliseconds. It is compared to the month/year entered to make sure that the month/year isn’t in the past:

[[ Now.addDays(-Now.getDate()).valueOf() ]]

Live sample

File: check_month_date.rp (48.1 KB)

Thank you so much Joseph! That’s perfect!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.