Just to give some background on what I am trying to do:
- I am in the US on a US machine
- I am using chrome
- I change my machine settings in control panel -> region and language to "English (United Kingdom)"
- under Chrome -> settings -> Language and Input settings, I removed "English(US)" and added "English (United Kingdom)"
I have an html page with one input box, and I want to validate that the text in the input box is a valid date based on the user client locale. So in the US user can enter "11/20/2013", and a user in UK can enter "20/11/2013".
<input type="text" id="dt" />
<input type="button" id="validate" value="validate" />
<script>
$(document).ready(function() {
$('#validate').click( function() {
if (isNaN(Date.parse($('#dt').val())) == true)
alert('date is invalid!');
else
alert('valid date');
});
});
</script>
It seems that Date.parse() is always expecting US format (DD/MM/YYYY). Any idea how I can get a validation based on the client locale?