Read EDIT 2 at bottom
Original post:
I have this jQuery validator method to check for a valid YYYY-MM-DD date:
$.validator.addMethod("myDate", function(value, element){
var validformat = /^\d\d\d\d\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/;
return validformat.test(value);
}, "Please enter a valid YYYY-MM-DD date");
It works fine on my computer – returns false when expected and true when expected. However, on my Android phone it always returns false – the input always says “Please enter a valid YYYY-MM-DD date” even when the date is valid.
Do any regex methods such as .test() work differently on Android (and possibly other phones), or is this a jQuery Validator bug?
EDIT: I have tried changing validformat.test(value) to value.match(validformat) with the same result – works on computer, not on phone.
EDIT 2: Ok even commenting everything else out inside the method and typing return true; still yields the error on my phone. Definitely a jQuery validator problem. Need a workaround though!
I have just checked on an Android 2.3 phone. It works perfectly.
Therefore, I blame it on Android 2.2 only. So here’s my little fix:
Annoying hacks 🙂