Search code examples
validationmagentomagento-1.5

Magento date of birth field validation is not working properly


In Magento registration page validation is not allowing me to submit the form for some valid date's.

For example :-

08/24/1988
MM/DD/YYYY

the above date is not working for me. The field class are

input-text validate-custom validation-failed

I found js in the source like below

var customer_dob = new Varien.DOB('.customer-dob', false, '%m/%e/%y'); 

where may be the wrong.Can some anyone suggest me.

Mage version : 1.5.1.0


Solution

  • The error is found in /js/varien/js.js, line 438.

    var error = false, day = parseInt(this.day.value) || 0, month = parseInt(this.month.value) || 0, year = parseInt(this.year.value) || 0;
    

    Obviously, varien fell for the all too well-known parseInt Bug/Feature.

    In short, before ES5, all strings starting with 0 are treated as an octal/base-8 number. Since 08 doesn't exist in base-8, parseInt-ing it evaluates to 0.

    parseInt() happens to take a second optional argument indicating the base it should be using for the interpretation.

    parseInt('8');      // => 8
    parseInt('08');     // => 0
    parseInt('08', 10); // => 8
    

    So, the solution to your problem is to patch the line mentioned above to read

    var error = false, day = parseInt(this.day.value, 10) || 0, month = parseInt(this.month.value, 10) || 0, year = parseInt(this.year.value, 10) || 0;
    

    Cheers!