My co-worker came up with a regex that validate dates... and it even validates leap years!
-
please, tell me this has a bug:
"^(((0[1-9]|[12]\\d|3[01])\\/(0[13578]|1[02])\\/((19|[2-9]\\d)\\d{2}))|((0[1-9]|[12]\\d|30)\\/(0[13456789]|1[012])\\/((19|[2-9]\\d)\\d{2}))|((0[1-9]|1\\d|2[0-8])\\/02\\/((19|[2-9]\\d)\\d{2}))|(29\\/02\\/((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
-
please, tell me this has a bug:
"^(((0[1-9]|[12]\\d|3[01])\\/(0[13578]|1[02])\\/((19|[2-9]\\d)\\d{2}))|((0[1-9]|[12]\\d|30)\\/(0[13456789]|1[012])\\/((19|[2-9]\\d)\\d{2}))|((0[1-9]|1\\d|2[0-8])\\/02\\/((19|[2-9]\\d)\\d{2}))|(29\\/02\\/((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$"
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
That's a very long expression. This is a shorter expression that validate dates:
^\d{4}[- /.](0?[1-9]|1[0-2])[- /.](0?[1-9]|[12][1-9]|3[01])$
Expresso[^] is a good tool to create regular expressions.
In some cases, my signature will be longer than my message...
<em style="color:red"> <b>ProgramFOX</b></em>
ProgramFOX
-
That's a very long expression. This is a shorter expression that validate dates:
^\d{4}[- /.](0?[1-9]|1[0-2])[- /.](0?[1-9]|[12][1-9]|3[01])$
Expresso[^] is a good tool to create regular expressions.
In some cases, my signature will be longer than my message...
<em style="color:red"> <b>ProgramFOX</b></em>
ProgramFOX
thanks for the reply, we actually found a bug on that expression when entering 01/01/2013 (dd/MM/yyyy), for some reason, this value was rejected...
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
-
thanks for the reply, we actually found a bug on that expression when entering 01/01/2013 (dd/MM/yyyy), for some reason, this value was rejected...
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
Sentenryu wrote:
thanks for the reply
You're welcome!
Sentenryu wrote:
dd/MM/yyyy
My expression is for yyyy/MM/dd. An expression for dd/MM/yyyy:
^(0?[1-9]|[12][1-9]|3[01])[- /.](0?[1-9]|1[0-2])[- /.]\d{4}$
In some cases, my signature will be longer than my message...
<em style="color:red"> <b>ProgramFOX</b></em>
ProgramFOX
-
Sentenryu wrote:
thanks for the reply
You're welcome!
Sentenryu wrote:
dd/MM/yyyy
My expression is for yyyy/MM/dd. An expression for dd/MM/yyyy:
^(0?[1-9]|[12][1-9]|3[01])[- /.](0?[1-9]|1[0-2])[- /.]\d{4}$
In some cases, my signature will be longer than my message...
<em style="color:red"> <b>ProgramFOX</b></em>
ProgramFOX
-
There's a difference between a valid date and a valid date format. A regex is good for checking formats, but I don't think it works for checking whether a day exists.
In some cases, my signature will be longer than my message...
<em style="color:red"> <b>ProgramFOX</b></em>
ProgramFOX
-
thanks for the reply, we actually found a bug on that expression when entering 01/01/2013 (dd/MM/yyyy), for some reason, this value was rejected...
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)