regex for a date of birth

3532
8
03-20-2020 01:31 PM
ryanEvanczyk
Occasional Contributor

I have a text field with a input mask (99-99-9999) and a hit (mm-dd-yyyy) where user inputs a DOB. This field is then used to calculate the Age of the person.

I'm trying to write a regex so that  a month of 13 and day of 32 are not allowed and I can't seem to get the syntax correct in Survey 123 - it appears to be correct in online regex checkers....

The regex is as follows:

regex(.,'^((0[1-9])|(1[12]))-((0[1-9])|(1[\d])|(2[\d])|(3[01]))-([\d]{4})$')

Am I missing something else?

Cheers,

RyanE

Tags (1)
0 Kudos
8 Replies
BenTurrell
Occasional Contributor III

Hey Ryan Evanczyk‌,

I tried out your regex in a super simple Survey123 form and it seems to work fine. I've attached the form. If you can upload your form I can take a look for you.

Thanks,

Ben


If this answer was helpful please mark it as helpful. If this answer solved your question please mark it as the answer to help others who have the same question.

ryanEvanczyk
Occasional Contributor

Hi Ben,

So frustrating.

 

I originally had written the regex to be for a dateTime stamp (yyyy-mm-dd hh:mm) and it was working. When I removed the time portion and switched the date around to be mm-dd-yyyy it stopped working.

 

I've tried every combination I can think of for the regex with different syntax using the online regex checkers. I also tried copying and pasting just the values of the whole surey into a new survey and that also did not work.

 

The form is attached. Look at line 54.

Thanks for your help,

RyanE

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Ryan,

Is there a reason you don't want to use a date question?  That would seem to be more appropriate than text in a pattern.

0 Kudos
ryanEvanczyk
Occasional Contributor

The main reason is that it seemed easier to fill out a text field than the date question. We use web books to complete our forms - generally the user has the computer in their lap while they type. Using the touchpad mouse to adjust the dates (and times) was more difficult for people than just typing in the numbers. Specifically, with the dob question, what was difficult for people was spinning that wheel for the year.

ryanEvanczyk
Occasional Contributor

This is the error I keep getting.

I should have mentioned earlier that our users are not always the most computer savy folks. This is the secondary reason for the text fields over the date and time fields - just typing the numbers is more straight forward for some of them.

0 Kudos
JamesTedrick
Esri Esteemed Contributor

Hi Ryan,

There seem to be some extra (hidden) characters at the end of the constraint calculation.  Deleting the closing parenthesis and re-typing it in got the form to work for me.

ryanEvanczyk
Occasional Contributor

That worked!

Thanks so much for your time on this.

Cheers,

RyanE

0 Kudos
Gerhard
New Contributor III

Just came across this, looks like there's a zero for the second month digit which would exclude October.

regex(.,'^((0[1-9])|(1[012]))-((0[1-9])|(1[\d])|(2[\d])|(3[01]))-([\d]{4})$')

Best,

Gerhard
0 Kudos