Help with validate code

To list,

I’m trying to ensure that a date & time entry for a custom field is correct.
I am using the following code in the validation box:

(?#Date mm/dd/yyyy
hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])
(0[0-9]|1[0-4]):(0[0-9]|1[0-9]))?$

I also tried:

(?#Date mm/dd/yyyy
hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])
(0[1-9]|1[0-2]):(0[0-9]|1[0-9]))?$

and that didn’t work either. I get this error message:

“Could not add new custom field value: Input must match [Date mm/dd/yyyy
hh:mm-military]”.

I figured the problem was with my “time” code, but what do I know? ;-).

Any help would be greatly appreciated.

Kenn
LBNL

(平成23/05/10 16:00), Kenneth Crocker wrote:

To list,

I’m trying to ensure that a date & time entry for a custom field is
correct. I am using the following code in the validation box:

(?#Date mm/dd/yyyy
hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])
(0[0-9]|1[0-4]):(0[0-9]|1[0-9]))?$

I also tried:

(?#Date mm/dd/yyyy
hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])
(0[1-9]|1[0-2]):(0[0-9]|1[0-9]))?$

and that didn’t work either. I get this error message:

“Could not add new custom field value: Input must match [Date mm/dd/yyyy
hh:mm-military]”.

I figured the problem was with my “time” code, but what do I know? ;-).

Any help would be greatly appreciated.

Kenn
LBNL

Yeah, this looks like your regex is failing to match against whatever
you’re putting into the field.

What values are you trying to put into this custom field that you expect
to work?

Shawn,

I enter (without the quotes) “05/02/2011 03:29”. There is a blank between
“2011” and “03:29”.

I don’t see why it doesn’t like it?

Kenn
LBNLOn Tue, May 10, 2011 at 1:02 PM, Shawn M Moore sartak@bestpractical.comwrote:

(平成23/05/10 16:00), Kenneth Crocker wrote:

To list,

I’m trying to ensure that a date & time entry for a custom field is
correct. I am using the following code in the validation box:

(?#Date mm/dd/yyyy

hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])
(0[0-9]|1[0-4]):(0[0-9]|1[0-9]))?$

I also tried:

(?#Date mm/dd/yyyy

hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])
(0[1-9]|1[0-2]):(0[0-9]|1[0-9]))?$

and that didn’t work either. I get this error message:

“Could not add new custom field value: Input must match [Date mm/dd/yyyy
hh:mm-military]”.

I figured the problem was with my “time” code, but what do I know? ;-).

Any help would be greatly appreciated.

Kenn
LBNL

Yeah, this looks like your regex is failing to match against whatever
you’re putting into the field.

What values are you trying to put into this custom field that you expect to
work?

(平成23/05/10 16:19), Kenneth Crocker wrote:

Shawn,

I enter (without the quotes) “05/02/2011 03:29”. There is a blank
between “2011” and “03:29”.

I don’t see why it doesn’t like it?

Your regex is buggy.

perl -le ‘“05/02/2011 03:29” =~ qr{(?#Date mm/dd/yyyy
hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])
(0[0-9]|1[0-4]):(0[0-9]|1[0-9]))?$}; print $&’

prints nothing, which means it didn’t match. Your minute part will only
match 00-19. 1[0-9] should probably be [1-5][0-9]

To list,

I’m trying to ensure that a date & time entry for a custom field is correct.

You may also:

  • use the patch [1] if you’re running 3.8.x to have a “Date” type for
    customfields
  • upgrade to 4.0.0 which has builtin date/time customfields :slight_smile:

[1]
http://issues.bestpractical.com/Ticket/Display.html?id=8721&user=guest&pass=guest

Shawn & Emmanuel,

I got it. Thanks:

(?#Date mm/dd/yyyy
hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])
(0[1-9]|1[0-9]|2[0-4]):([0-5][0-9]))?$

Kenn
LBNLOn Tue, May 10, 2011 at 1:36 PM, Emmanuel Lacour elacour@easter-eggs.comwrote:

On Tue, May 10, 2011 at 01:00:07PM -0700, Kenneth Crocker wrote:

To list,

I’m trying to ensure that a date & time entry for a custom field is
correct.

You may also:

  • use the patch [1] if you’re running 3.8.x to have a “Date” type for
    customfields
  • upgrade to 4.0.0 which has builtin date/time customfields :slight_smile:

[1]

http://issues.bestpractical.com/Ticket/Display.html?id=8721&user=guest&pass=guest

Shawn & Emmanuel,

I got it. Thanks:

(?#Date mm/dd/yyyy
hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])
(0[1-9]|1[0-9]|2[0-4]):([0-5][0-9]))?$

To nitpick: 00 is a valid hour, 24 is not.

Thomas

Thomas,

Geez! Thanks.

Kenn
LBNLOn Tue, May 10, 2011 at 2:55 PM, Thomas Sibley trs@bestpractical.comwrote:

On 05/10/2011 05:47 PM, Kenneth Crocker wrote:

Shawn & Emmanuel,

I got it. Thanks:

(?#Date mm/dd/yyyy

hh:mm-military)^((0[1-9]|1[0-2])/(0[1-9]|[1-2][0-9]|3[0-1])/([1-2][0-9][0-9][0-9])

(0[1-9]|1[0-9]|2[0-4]):([0-5][0-9]))?$

To nitpick: 00 is a valid hour, 24 is not.

Thomas