Skip to main content
Solved

Regex to check for a valid date

  • February 27, 2024
  • 3 replies
  • 579 views

Forum|alt.badge.img+8
  • Flight Specialist | Tier 4
  • 63 replies

I need to check a string for valid date values in either m/d/yyyy or mm/dd/yyyy format. In my regex checker app the following two expressions work fine to identify valid dates:

/^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.]((?:19|20)\d\d)$$/

and 

/^([1-9]|1[012])[- \/.]([1-9]|[12][0-9]|3[01])[- \/.]((?:19|20)\d\d)$$/

Note the double dollar signs for AA

When I try and use these expressions in an IF Action using the REGEX Tools it does not recognize the valid dates. Any suggestions?

Best answer by r.singh

@JMarino 

We don’t have option to match a string pattern like you have use in code. 

Other optons  you can  try. Use the String → Find action and add your regex pattern, select “A regular expression”  and the output will always be 1 if it matches otherwise it will be 0.

 

Please try below expression in string find as your expression has an issue.

02/28/2023

^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.]((?:19|20)\d\d)$$

 

2/28/2023

^([1-9]|1[012])[- \/.]([1-9]|[12][0-9]|3[01])[- \/.]((?:19|20)\d\d)$$

 

 

 

If it help please mark as resolved.

View original
Did this topic help answer your question?

3 replies

Forum|alt.badge.img+4
  • Navigator | Tier 3
  • 14 replies
  • February 28, 2024

@JMarino Can you share screenshot for line of code that you are using?


Forum|alt.badge.img+8
  • Author
  • Flight Specialist | Tier 4
  • 63 replies
  • February 28, 2024

Doesn’t matter what I put in the variable. I always get the message box for No Match


Forum|alt.badge.img+4
  • Navigator | Tier 3
  • 14 replies
  • Answer
  • February 28, 2024

@JMarino 

We don’t have option to match a string pattern like you have use in code. 

Other optons  you can  try. Use the String → Find action and add your regex pattern, select “A regular expression”  and the output will always be 1 if it matches otherwise it will be 0.

 

Please try below expression in string find as your expression has an issue.

02/28/2023

^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.]((?:19|20)\d\d)$$

 

2/28/2023

^([1-9]|1[012])[- \/.]([1-9]|[12][0-9]|3[01])[- \/.]((?:19|20)\d\d)$$

 

 

 

If it help please mark as resolved.


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