-4

First 10 digits with space is working fine but my date regex is failing.

^(\d{6}\s{2}|\d{8})\/(\d{1}\s|\d{2})\s\/(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Uttam Kumar
  • 17
  • 1
  • 6
  • what is this input and are you looking at regex only solution? – gurvinder372 Nov 07 '17 at 13:29
  • 1
    Your date regex seems way too complex. There is obvioulsy simpler ways to do it, please make some research. – sjahan Nov 07 '17 at 13:45
  • That's one nasty monster regex. – John Weisz Nov 07 '17 at 13:50
  • Thanks all , I tried other approaches using react-input-mask but there is no luck. Earlier tried with ^(\d{6}\s{2}|\d{8})/(\d{1}\s|\d{2})\s\d{2}/\d{2}/\d{4}$ now all i need in date regex to be added for the above one. – Uttam Kumar Nov 07 '17 at 13:52
  • But you haven't told us what you want to validate and what is acceptance criterion? – gurvinder372 Nov 07 '17 at 14:11
  • 6 to 8 digits with spaces allowed (999 9 99) "/" two digits (99)" "DD/MM/YYYY in date DD must be below or equal 31 , MM must be 12 or below and YYYY can be anything but must be 4 digits. @gurvinder372 – Uttam Kumar Nov 07 '17 at 14:40

1 Answers1

0

Got a Solution But where feb must be 28/29 days apart from this all others are working please look at the pattern

^([0-9]{6}|[0-9]{8})([\s]{2}|[\s]{0})[/]{1}[0-9]{2}[\s]{1}(0[0-9]|[0-2]|1[0-2])[/]{1}([0-9]|[0-2][0-9]|3[0-1])[/]{1}[0-9]{4}$

Uttam Kumar
  • 17
  • 1
  • 6