Date Regex within workflow script

I want to do a regex test on a field to see if it’s formatted as a expected date format. Using a regex builder it’s told me to use:

\d\d/\d\d/\d\d\d\d

But I can’t get the command to work, it keeps complaining when I try assigning the regex value, What should I be putting around the regex?

image

Try:

var regex = /^\d{2}\/\d{2}\/\d{4}$

Thanks that’s perfect.

Got another now which I’m trying to test of a character is a number or upper case letter. My understanding is the below should work but it’s flagging lowercase too.

var regex = /[1]|[A-Z]$/i

I’ve tried just the /[2]$/i but that’s still picking up lowercase letters.


  1. 0-9 ↩︎

  2. A-Z ↩︎

The reason why this happens is because you have applied the case-insenitive search flag i. Apply something like /[A-Z0-9]/.test(inputDate) instead when you would like to test whether a single character is a number or an upper case letter.

Tip: See Regular expressions - JavaScript | MDN for more information about the optional flags available.

Also a great tool to try your regex expression: Regex Online