0
const dateRegex = new RegExp('/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/')
        if (!formData.dob || !dateRegex.test(formData.dob)) {
            formErrors.dob = "date of birth is required"
        }

The RegExp I am using for the date of birth isn't working. Can someone help me with this, please?

regex

Temisan Momodu
  • 99
  • 1
  • 1
  • 6
  • 1
    Does this answer your question? [Javascript date regex DD/MM/YYYY](https://stackoverflow.com/questions/5465375/javascript-date-regex-dd-mm-yyyy) – Anindya Dey Apr 26 '22 at 11:29

1 Answers1

1

Try using this RegEx

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

You can read more about this regex in this post: Date of birth validation by using regular expression

Checkout Coenwulf's answer

Cores13
  • 31
  • 4
  • I tried it as well as the reference you suggested, but they both didn't work. I guess my situation requires a different type of approach. I am currently using Next js & TypeScript. – Temisan Momodu Apr 26 '22 at 18:32