views:

643

answers:

2

Jquery test the validity of a date via:

!/Invalid|NaN/.test(new Date(value))

new Date(dateString) is the same as Date.parse(dateString) and uses browser/os locale to parse the string.

im trying to parse DD/MM/YYYY but i get an error because my browser is looking for MM/DD/YYYY. Since my product will be used only by DD/MM people, i want to force this behaviour.

I could write a custom validator, but is it possible to change the browser locale via javascript as well?

A: 

You can't change the locale, as there is no such feature in the EMCAScript specification.

However, there is a nice package called php.js that implements PHP functions in JavaScript.

Two of the functions are setlocale() and date(). You can use them.

Sagi
Wow, I would never ever recommend that anybody touch that php.js code with a pole of arbitrary length. Yuk.
Pointy
He can always watch the dependencies and use only the necessary functions.
Sagi
im not using the php.js, accepted for the information that its impossible to change locale in javascript
bortao
Wow. Suggesting, not only that he utilize a huge library for this single purpose… but suggesting, specifically, a library that emulates *PHP*‽ That’s… irresponsible, to say the least. -1’d.
elliottcable
A: 

If your product will only be used by DD/MM/YYYY people, set your browser to a DD/MM/YYYY supporting locale.

Gipsy King