I need a regex, that validates this 2 patterns:
yyyy-MM-dd HH:mm:ss
and
yyyy-MM-dd HH:mm:ss
the second one is for Get
parameters of a url.. thats why there is a
in there.
Edit:
I tired this one:
^\d{4}\/([0]\d|[1][0-2])\/([0-2]\d|[3][0-1])(\s([0]\d|[1][0-2])(:[0-5]\d){1,2})*\s*([aApP][mM]{0,2})?$
but it does not work
CodePudding user response:
[0-9]{4}-[0-9]{2}-[0-9]{2}(?: | )[0-9]{2}:[0-9]{2}:[0-9]{2}
This'll work if you're in JavaScript.
You can also place the separate parts in capture groups and check them if you need to validate e.g. that month is less than 12