Locale Date Validation

39 views
Skip to first unread message

Richard Herbert

unread,
Mar 22, 2012, 6:46:01 AM3/22/12
to valida...@googlegroups.com
How are people handling locale specific date validation on both the client and server-side?

I think I'm right in saying that the "defaultLocale" config setting only affects multiple languages support not regional date formats.

So if you have setLocale("en_GB") in your Application.cfc how can you get VT to discriminate between...

1/31/12

...and...

31/1/12

Thoughts, best practice and advice welcome.

Richard

John Whish

unread,
Mar 22, 2012, 8:05:05 AM3/22/12
to valida...@googlegroups.com
Hi Richard,

The validate date method just checks with IsValid(date, x) server side and the client side is similar. In fact on the client side, different browsers will accept different values as a valid date, which makes life tricky. 

In the past where I've needed to do this I've created by own validators. The JS will be something like (off the top of my head):

function(value, element) {
var exploded = value.split(/\-\./); // split string by delimiter(s)
var theDate = new Date(exploded[2], exploded[1]-1, exploded[0]);
return this.optional(element) || !/Invalid|NaN/.test(theDate);
}


Richard

--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To view this discussion on the web visit https://groups.google.com/d/msg/validatethis/-/PaOViDnHlV8J.
To post to this group, send email to valida...@googlegroups.com.
To unsubscribe from this group, send email to validatethis...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/validatethis?hl=en.

Bob Silverberg

unread,
Mar 22, 2012, 1:59:50 PM3/22/12
to valida...@googlegroups.com
Yeah, there's nothing built into VT to support this, but you could,
perhaps, create a "locale aware" validator which behaves differently
depending on what the current locale is (assuming you've called
setLocale()). It might be interesting to see if you can some up with
something that would do that.

Cheers,
Bob

--
Bob Silverberg
www.silverwareconsulting.com

Richard Herbert

unread,
Mar 23, 2012, 11:30:07 AM3/23/12
to valida...@googlegroups.com
Yes, I was thinking about overwriting the VT server-side date validation functions (not skilled enough to do the client-side). Looking around the doc's I couldn't see anything about overriding validation types only creating new ones. Should I pursue that route with something like...
<rule type="dateLocale" />
Your thoughts and direction to other reading sources would be welcome.

Richard


>> For more options, visit this group at
>> http://groups.google.com/​group/validatethis?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis" group.
> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to


> For more options, visit this group at
> http://groups.google.com/​group/validatethis?hl=en.

Bob Silverberg

unread,
Mar 23, 2012, 11:46:02 AM3/23/12
to valida...@googlegroups.com
You can override an existing one (I believe) simply by creating one of
your own in your own folder with the same name.

Bob

>> >> validatethis...@googlegroups.com.


>> >> For more options, visit this group at
>> >> http://groups.google.com/group/validatethis?hl=en.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "ValidateThis" group.
>> > To post to this group, send email to valida...@googlegroups.com.
>> > To unsubscribe from this group, send email to

>> > validatethis...@googlegroups.com.


>> > For more options, visit this group at
>> > http://groups.google.com/group/validatethis?hl=en.
>>
>> --
>> Bob Silverberg
>> www.silverwareconsulting.com
>

> --
> You received this message because you are subscribed to the Google Groups
> "ValidateThis" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/validatethis/-/p77H2pcmUxkJ.


>
> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to

> validatethis...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages