Skip to main content
Nintex Community Menu Bar

Time Range Validation and DateTime Control Regular Expressions

  • August 12, 2021
  • 3 replies
  • 382 views
  • Translate

I'm working on a form where I need to check if the user has entered a time outside of a certain range (as an example, let's use 12:00 PM - 10:00 PM). I have this sort of working using invalidate rules but the validation doesn't update until the user either selects/enters a date or tries to submit the form. So if a user changes the time from 12:00 AM to 3:00 PM, the form would still say that the time was out of range until the user changes the date or clicks save/submit. Is this normal?

 

In trying to deal with this, I thought maybe a regular expression validation on the control would be more effective/responsive, but I haven't been able to figure out a valid regular expression. Does anyone know what format the date is in when comparing to a regular expression from the DateTime control's "Use a regular expression" validation option? I've tried the format MM/dd/yyyy hh:mm:ss tt (11/28/2021 10:30:00 AM), but it doesn't seem to work even without trying to check for specific values in hours/minutes.

Did this topic help you find an answer to your question?

3 replies

  • Author
  • 2 replies
  • August 13, 2021

I forgot to mention, I'm working in responsive forms, not classic.

Translate

Forum|alt.badge.img+8
  • Scholar
  • 57 replies
  • August 16, 2021

Add a calculated control value to the form, with the formula: 

 

if(and(not(isNullorEmpty(Date)),or(greaterThanOrEqual(formatDate(Date,"HH"),22),lessThanOrEqual(formatDate(Date,"HH"),12))),"Please select a time between noon and 10PM","")

where Date is your column selected from the Named Controls tab. 

This will not show a message until they have selected a date. 

 

If you want the message to appear before they even select a date, then use the simpler formula:

if(or(greaterThanOrEqual(formatDate(Date,"HH"),22),lessThanOrEqual(formatDate(Date,"HH"),12)),"Please select a time between noon and 10PM","") , again using the Named Control for your date column in place of Date.

 

Of course, you could use this formula as an invalidate rule, but if you want them to see in real time, the calculated value works when they change the value.

 

If you want a bold red message, simply add a Label control with the message in bold red text, and use the following formula as a rule to hide the label:

not(and(not(isNullorEmpty(Date)),or(greaterThanOrEqual(formatDate(Date,"HH"),22),lessThanOrEqual(formatDate(Date,"HH"),12)))) where Date is the Named Control of your field.

 

Adjust the greaterThanOrEqual to greaterThan and lessThanOrEqual to lessThan as appropriate for your conditions.

 

Best of luck!

Translate

  • Author
  • 2 replies
  • August 19, 2021

Thanks so much for your help -- I'm still having some issues getting the formatting to work, but this has helped a lot. 🙂 I'm working with validation rules as well so the form wouldn't submit with invalid dates, but this technique allows me to hide the messages from validation rules too. Thanks again and have a good one

Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings