Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
70
rated 0 times [  77] [ 7]  / answers: 1 / hits: 44105  / 15 Years ago, fri, march 5, 2010, 12:00:00

jQuery tests 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.



I'm 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?


More From » browser

 Answers
5

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.


[#97420] Tuesday, March 2, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kiley

Total Points: 733
Total Questions: 118
Total Answers: 94

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;