浏览代码

Merge branch 'master' into v0.5.0

Conflicts:
	dist/js/bootstrapValidator.min.js
nghuuphuoc 11 年之前
父节点
当前提交
ed3798bd3a
共有 6 个文件被更改,包括 459 次插入60 次删除
  1. 7 6
      CHANGELOG.md
  2. 226 27
      dist/js/bootstrapValidator.js
  3. 22 0
      src/js/bootstrapValidator.js
  4. 1 12
      src/js/validator/date.js
  5. 200 6
      src/js/validator/id.js
  6. 3 9
      src/js/validator/vat.js

+ 7 - 6
CHANGELOG.md

@@ -6,6 +6,7 @@
 
 ## v0.4.5 (not released yet)
 
+* Add ```$.fn.bootstrapValidator.helpers.date``` for validating a date, re-used in ```date```, ```id```, [```vat```](http://bootstrapvalidator.com/validators/vat/) validators
 * [#233](https://github.com/nghuuphuoc/bootstrapvalidator/issues/233): Add ```threshold``` option
 * [#232](https://github.com/nghuuphuoc/bootstrapvalidator/issues/232): Add ```id``` validator
 * When parsing options from HTML attributes, don't add the field which hasn't validators. It improves fixes for [#191](https://github.com/nghuuphuoc/bootstrapvalidator/issues/191), [#223](https://github.com/nghuuphuoc/bootstrapvalidator/issues/223)
@@ -13,12 +14,12 @@
 ## v0.4.4 (2014-05-05)
 
 * Add ```$.fn.bootstrapValidator.helpers.mod_11_10``` method that implements modulus 11, 10 (ISO 7064) algorithm. The helper is then reused in validating [German and Croatian VAT](http://bootstrapvalidator.com/validators/vat/) numbers
-* Add ```$.fn.bootstrapValidator.helpers.mod_37_36``` method that implements modulus 37, 36 (ISO 7064) algorithm, used in GRid validator
-* [#213](https://github.com/nghuuphuoc/bootstrapvalidator/issues/213): Add EAN (International Article Number) validator
-* [#214](https://github.com/nghuuphuoc/bootstrapvalidator/issues/214): Add GRId (Global Release Identifier) validator
-* [#215](https://github.com/nghuuphuoc/bootstrapvalidator/issues/215): Add IMEI (International Mobile Station Equipment Identity) validator
-* [#216](https://github.com/nghuuphuoc/bootstrapvalidator/issues/216): Add ISMN (International Standard Music Number) validator
-* [#217](https://github.com/nghuuphuoc/bootstrapvalidator/issues/217): Add ISSN (International Standard Serial Number) validator
+* Add ```$.fn.bootstrapValidator.helpers.mod_37_36``` method that implements modulus 37, 36 (ISO 7064) algorithm, used in [GRid validator](http://bootstrapvalidator.com/validators/grid/)
+* [#213](https://github.com/nghuuphuoc/bootstrapvalidator/issues/213): Add [EAN (International Article Number) validator](http://bootstrapvalidator.com/validators/ean/)
+* [#214](https://github.com/nghuuphuoc/bootstrapvalidator/issues/214): Add [GRId (Global Release Identifier) validator](http://bootstrapvalidator.com/validators/grid/)
+* [#215](https://github.com/nghuuphuoc/bootstrapvalidator/issues/215): Add [IMEI (International Mobile Station Equipment Identity) validator](http://bootstrapvalidator.com/validators/imei/)
+* [#216](https://github.com/nghuuphuoc/bootstrapvalidator/issues/216): Add [ISMN (International Standard Music Number) validator](http://bootstrapvalidator.com/validators/ismn/)
+* [#217](https://github.com/nghuuphuoc/bootstrapvalidator/issues/217): Add [ISSN (International Standard Serial Number) validator](http://bootstrapvalidator.com/validators/issn/)
 * [#191](https://github.com/nghuuphuoc/bootstrapvalidator/issues/191), [#223](https://github.com/nghuuphuoc/bootstrapvalidator/issues/223): Support using both the ```name``` attribute and ```selector``` option for field
 * [#206](https://github.com/nghuuphuoc/bootstrapvalidator/issues/206): Indicate success/error tab
 * [#220](https://github.com/nghuuphuoc/bootstrapvalidator/issues/220): Add UK postcode support for the [```zipCode``` validator](http://bootstrapvalidator.com/validators/zipCode/)

+ 226 - 27
dist/js/bootstrapValidator.js

@@ -923,6 +923,28 @@
     // Helper methods, which can be used in validator class
     $.fn.bootstrapValidator.helpers = {
         /**
+         * Validate a date
+         *
+         * @param {Number} year The full year in 4 digits
+         * @param {Number} month The month number
+         * @param {Number} day The day number
+         * @returns {Boolean}
+         */
+        date: function(year, month, day) {
+            if (year < 1000 || year > 9999 || month == 0 || month > 12) {
+                return false;
+            }
+            var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+            // Update the number of days in Feb of leap year
+            if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
+                numDays[1] = 29;
+            }
+
+            // Check the day
+            return (day > 0 && day <= numDays[month - 1]);
+        },
+
+        /**
          * Implement Luhn validation algorithm ((http://en.wikipedia.org/wiki/Luhn))
          * Credit to https://gist.github.com/ShirtlessKirk/2134376
          *
@@ -1414,18 +1436,7 @@
             month = parseInt(month, 10);
             year  = parseInt(year, 10);
 
-            if (year < 1000 || year > 9999 || month == 0 || month > 12) {
-                return false;
-            }
-
-            var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
-            // Update the number of days in Feb of leap year
-            if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
-                numDays[1] = 29;
-            }
-
-            // Check the day
-            return (day > 0 && day <= numDays[month - 1]);
+            return $.fn.bootstrapValidator.helpers.date(year, month, day);
         }
     };
 }(window.jQuery));
@@ -1902,6 +1913,96 @@
         },
 
         /**
+         * Validate Unique Master Citizen Number which uses in
+         * - Bosnia and Herzegovina (country code: BA)
+         * - Macedonia (MK)
+         * - Montenegro (ME)
+         * - Serbia (RS)
+         * - Slovenia (SI)
+         *
+         * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
+         * @param {String} value The ID
+         * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
+         * @returns {Boolean}
+         */
+        _validateJMBG: function(value, countryCode) {
+            if (!/^\d{13}$/.test(value)) {
+                return false;
+            }
+            var day   = parseInt(value.substr(0, 2), 10),
+                month = parseInt(value.substr(2, 2), 10),
+                year  = parseInt(value.substr(4, 3), 10),
+                rr    = parseInt(value.substr(7, 2), 10),
+                k     = parseInt(value.substr(12, 1), 10);
+
+            // Validate date of birth
+            // FIXME: Validate the year of birth
+            if (day > 31 || month > 12) {
+                return false;
+            }
+
+            // Validate checksum
+            var sum = 0;
+            for (var i = 0; i < 6; i++) {
+                sum += (7 - i) * (parseInt(value.charAt(i)) + parseInt(value.charAt(i + 6)));
+            }
+            sum = 11 - sum % 11;
+            if (sum == 10 || sum == 11) {
+                sum = 0;
+            }
+            if (sum != k) {
+                return false;
+            }
+
+            // Validate political region
+            // rr is the political region of birth, which can be in ranges:
+            // 10-19: Bosnia and Herzegovina
+            // 20-29: Montenegro
+            // 30-39: Croatia (not used anymore)
+            // 41-49: Macedonia
+            // 50-59: Slovenia (only 50 is used)
+            // 70-79: Central Serbia
+            // 80-89: Serbian province of Vojvodina
+            // 90-99: Kosovo
+            switch (countryCode.toUpperCase()) {
+                case 'BA':
+                    return (10 <= rr && rr <= 19);
+                case 'MK':
+                    return (41 <= rr && rr <= 49);
+                case 'ME':
+                    return (20 <= rr && rr <= 29);
+                case 'RS':
+                    return (70 <= rr && rr <= 99);
+                case 'SI':
+                    return (50 <= rr && rr <= 59);
+                default:
+                    return true;
+            }
+
+            return true;
+        },
+
+        _ba: function(value) {
+            return this._validateJMBG(value, 'BA');
+        },
+        _mk: function(value) {
+            return this._validateJMBG(value, 'MK');
+        },
+        _me: function(value) {
+            return this._validateJMBG(value, 'ME');
+        },
+        _rs: function(value) {
+            return this._validateJMBG(value, 'RS');
+        },
+
+        /**
+         * Examples: 0101006500006
+         */
+        _si: function(value) {
+            return this._validateJMBG(value, 'SI');
+        },
+
+        /**
          * Validate Bulgarian national identification number (EGN)
          * Examples:
          * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
@@ -1928,9 +2029,7 @@
                 month -= 20;
             }
 
-            try {
-                var d = new Date(year, month, day);
-            } catch (ex) {
+            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                 return false;
             }
 
@@ -2013,9 +2112,7 @@
                 year += 100;
             }
 
-            try {
-                var d = new Date(year, month, day);
-            } catch (ex) {
+            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                 return false;
             }
 
@@ -2032,6 +2129,20 @@
         },
 
         /**
+         * Validate Slovak national identifier number (RC)
+         * Examples:
+         * - Valid: 7103192745, 991231123
+         * - Invalid: 7103192746, 1103492745
+         *
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _sk: function(value) {
+            // Slovakia uses the same format as Czech Republic
+            return this._cz(value);
+        },
+
+        /**
          * Validate Spanish personal identity code (DNI)
          * Examples:
          * - Valid: 54362315K, 54362315-K
@@ -2064,6 +2175,100 @@
                 return false;
             }
             return $.fn.bootstrapValidator.helpers.mod_11_10(value);
+        },
+
+        /**
+         * Validate Romanian numerical personal code (CNP)
+         * Examples:
+         * - Valid: 1630615123457, 1800101221144
+         * - Invalid: 8800101221144, 1632215123457, 1630615123458
+         *
+         * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _ro: function(value) {
+            if (!/^[0-9]{13}$/.test(value)) {
+                return false;
+            }
+            var gender = parseInt(value.charAt(0));
+            if (gender == 0 || gender == 7 || gender == 8) {
+                return false;
+            }
+
+            // Determine the date of birth
+            var year      = parseInt(value.substr(1, 2), 10),
+                month     = parseInt(value.substr(3, 2), 10),
+                day       = parseInt(value.substr(5, 2), 10),
+                // The year of date is determined base on the gender
+                centuries = {
+                    '1': 1900,  // Male born between 1900 and 1999
+                    '2': 1900,  // Female born between 1900 and 1999
+                    '3': 1800,  // Male born between 1800 and 1899
+                    '4': 1800,  // Female born between 1800 and 1899
+                    '5': 2000,  // Male born after 2000
+                    '6': 2000   // Female born after 2000
+                };
+            if (day > 31 && month > 12) {
+                return false;
+            }
+            if (gender != 9) {
+                year = centuries[gender + ''] + year;
+                if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
+                    return false;
+                }
+            }
+
+            // Validate the check digit
+            var sum    = 0,
+                weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
+                length = value.length;
+            for (var i = 0; i < length - 1; i++) {
+                sum += parseInt(value.charAt(i)) * weight[i];
+            }
+            sum = sum % 11;
+            if (sum == 10) {
+                sum = 1;
+            }
+            return (sum == value.charAt(length - 1));
+        },
+
+        /**
+         * Validate Swedish personal identity number (personnummer)
+         * Examples:
+         * - Valid: 8112289874, 811228-9874, 811228+9874
+         * - Invalid: 811228-9873
+         *
+         * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _se: function(value) {
+            if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
+                return false;
+            }
+            value = value.replace(/[^0-9]/g, '');
+
+            var year  = parseInt(value.substr(0, 2)) + 1900,
+                month = parseInt(value.substr(2, 2)),
+                day   = parseInt(value.substr(4, 2));
+            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
+                return false;
+            }
+
+            // Validate the last check digit
+            return $.fn.bootstrapValidator.helpers.luhn(value);
+        },
+
+        /**
+         * Validate San Marino citizen number
+         *
+         * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _sm: function(value) {
+            return /^\d{5}$/.test(value);
         }
     };
 }(window.jQuery));
@@ -3101,9 +3306,7 @@
                             month -= 20;
                         }
 
-                        try {
-                            var d = new Date(year, month, day);
-                        } catch (ex) {
+                        if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                             return false;
                         }
 
@@ -3288,9 +3491,7 @@
                     year += 100;
                 }
 
-                try {
-                    var d = new Date(year, month, day);
-                } catch (ex) {
+                if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                     return false;
                 }
 
@@ -3801,9 +4002,7 @@
                     year  = parseInt(value.substr(4, 2));
                 year = year + 1800 + parseInt(value.charAt(6)) * 100;
 
-                try {
-                    var d = new Date(year, month, day);
-                } catch (ex) {
+                if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                     return false;
                 }
 

+ 22 - 0
src/js/bootstrapValidator.js

@@ -922,6 +922,28 @@
     // Helper methods, which can be used in validator class
     $.fn.bootstrapValidator.helpers = {
         /**
+         * Validate a date
+         *
+         * @param {Number} year The full year in 4 digits
+         * @param {Number} month The month number
+         * @param {Number} day The day number
+         * @returns {Boolean}
+         */
+        date: function(year, month, day) {
+            if (year < 1000 || year > 9999 || month == 0 || month > 12) {
+                return false;
+            }
+            var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+            // Update the number of days in Feb of leap year
+            if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
+                numDays[1] = 29;
+            }
+
+            // Check the day
+            return (day > 0 && day <= numDays[month - 1]);
+        },
+
+        /**
          * Implement Luhn validation algorithm ((http://en.wikipedia.org/wiki/Luhn))
          * Credit to https://gist.github.com/ShirtlessKirk/2134376
          *

+ 1 - 12
src/js/validator/date.js

@@ -98,18 +98,7 @@
             month = parseInt(month, 10);
             year  = parseInt(year, 10);
 
-            if (year < 1000 || year > 9999 || month == 0 || month > 12) {
-                return false;
-            }
-
-            var numDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
-            // Update the number of days in Feb of leap year
-            if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) {
-                numDays[1] = 29;
-            }
-
-            // Check the day
-            return (day > 0 && day <= numDays[month - 1]);
+            return $.fn.bootstrapValidator.helpers.date(year, month, day);
         }
     };
 }(window.jQuery));

+ 200 - 6
src/js/validator/id.js

@@ -32,6 +32,96 @@
         },
 
         /**
+         * Validate Unique Master Citizen Number which uses in
+         * - Bosnia and Herzegovina (country code: BA)
+         * - Macedonia (MK)
+         * - Montenegro (ME)
+         * - Serbia (RS)
+         * - Slovenia (SI)
+         *
+         * @see http://en.wikipedia.org/wiki/Unique_Master_Citizen_Number
+         * @param {String} value The ID
+         * @param {String} countryCode The ISO country code, can be BA, MK, ME, RS, SI
+         * @returns {Boolean}
+         */
+        _validateJMBG: function(value, countryCode) {
+            if (!/^\d{13}$/.test(value)) {
+                return false;
+            }
+            var day   = parseInt(value.substr(0, 2), 10),
+                month = parseInt(value.substr(2, 2), 10),
+                year  = parseInt(value.substr(4, 3), 10),
+                rr    = parseInt(value.substr(7, 2), 10),
+                k     = parseInt(value.substr(12, 1), 10);
+
+            // Validate date of birth
+            // FIXME: Validate the year of birth
+            if (day > 31 || month > 12) {
+                return false;
+            }
+
+            // Validate checksum
+            var sum = 0;
+            for (var i = 0; i < 6; i++) {
+                sum += (7 - i) * (parseInt(value.charAt(i)) + parseInt(value.charAt(i + 6)));
+            }
+            sum = 11 - sum % 11;
+            if (sum == 10 || sum == 11) {
+                sum = 0;
+            }
+            if (sum != k) {
+                return false;
+            }
+
+            // Validate political region
+            // rr is the political region of birth, which can be in ranges:
+            // 10-19: Bosnia and Herzegovina
+            // 20-29: Montenegro
+            // 30-39: Croatia (not used anymore)
+            // 41-49: Macedonia
+            // 50-59: Slovenia (only 50 is used)
+            // 70-79: Central Serbia
+            // 80-89: Serbian province of Vojvodina
+            // 90-99: Kosovo
+            switch (countryCode.toUpperCase()) {
+                case 'BA':
+                    return (10 <= rr && rr <= 19);
+                case 'MK':
+                    return (41 <= rr && rr <= 49);
+                case 'ME':
+                    return (20 <= rr && rr <= 29);
+                case 'RS':
+                    return (70 <= rr && rr <= 99);
+                case 'SI':
+                    return (50 <= rr && rr <= 59);
+                default:
+                    return true;
+            }
+
+            return true;
+        },
+
+        _ba: function(value) {
+            return this._validateJMBG(value, 'BA');
+        },
+        _mk: function(value) {
+            return this._validateJMBG(value, 'MK');
+        },
+        _me: function(value) {
+            return this._validateJMBG(value, 'ME');
+        },
+        _rs: function(value) {
+            return this._validateJMBG(value, 'RS');
+        },
+
+        /**
+         * Examples: 0101006500006
+         */
+        _si: function(value) {
+            return this._validateJMBG(value, 'SI');
+        },
+
+        /**
          * Validate Bulgarian national identification number (EGN)
          * Examples:
          * - Valid: 7523169263, 8032056031, 803205 603 1, 8001010008, 7501020018, 7552010005, 7542011030
@@ -58,9 +148,7 @@
                 month -= 20;
             }
 
-            try {
-                var d = new Date(year, month, day);
-            } catch (ex) {
+            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                 return false;
             }
 
@@ -143,9 +231,7 @@
                 year += 100;
             }
 
-            try {
-                var d = new Date(year, month, day);
-            } catch (ex) {
+            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                 return false;
             }
 
@@ -162,6 +248,20 @@
         },
 
         /**
+         * Validate Slovak national identifier number (RC)
+         * Examples:
+         * - Valid: 7103192745, 991231123
+         * - Invalid: 7103192746, 1103492745
+         *
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _sk: function(value) {
+            // Slovakia uses the same format as Czech Republic
+            return this._cz(value);
+        },
+
+        /**
          * Validate Spanish personal identity code (DNI)
          * Examples:
          * - Valid: 54362315K, 54362315-K
@@ -194,6 +294,100 @@
                 return false;
             }
             return $.fn.bootstrapValidator.helpers.mod_11_10(value);
+        },
+
+        /**
+         * Validate Romanian numerical personal code (CNP)
+         * Examples:
+         * - Valid: 1630615123457, 1800101221144
+         * - Invalid: 8800101221144, 1632215123457, 1630615123458
+         *
+         * @see http://en.wikipedia.org/wiki/National_identification_number#Romania
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _ro: function(value) {
+            if (!/^[0-9]{13}$/.test(value)) {
+                return false;
+            }
+            var gender = parseInt(value.charAt(0));
+            if (gender == 0 || gender == 7 || gender == 8) {
+                return false;
+            }
+
+            // Determine the date of birth
+            var year      = parseInt(value.substr(1, 2), 10),
+                month     = parseInt(value.substr(3, 2), 10),
+                day       = parseInt(value.substr(5, 2), 10),
+                // The year of date is determined base on the gender
+                centuries = {
+                    '1': 1900,  // Male born between 1900 and 1999
+                    '2': 1900,  // Female born between 1900 and 1999
+                    '3': 1800,  // Male born between 1800 and 1899
+                    '4': 1800,  // Female born between 1800 and 1899
+                    '5': 2000,  // Male born after 2000
+                    '6': 2000   // Female born after 2000
+                };
+            if (day > 31 && month > 12) {
+                return false;
+            }
+            if (gender != 9) {
+                year = centuries[gender + ''] + year;
+                if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
+                    return false;
+                }
+            }
+
+            // Validate the check digit
+            var sum    = 0,
+                weight = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9],
+                length = value.length;
+            for (var i = 0; i < length - 1; i++) {
+                sum += parseInt(value.charAt(i)) * weight[i];
+            }
+            sum = sum % 11;
+            if (sum == 10) {
+                sum = 1;
+            }
+            return (sum == value.charAt(length - 1));
+        },
+
+        /**
+         * Validate Swedish personal identity number (personnummer)
+         * Examples:
+         * - Valid: 8112289874, 811228-9874, 811228+9874
+         * - Invalid: 811228-9873
+         *
+         * @see http://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _se: function(value) {
+            if (!/^[0-9]{10}$/.test(value) && !/^[0-9]{6}[-|+][0-9]{4}$/.test(value)) {
+                return false;
+            }
+            value = value.replace(/[^0-9]/g, '');
+
+            var year  = parseInt(value.substr(0, 2)) + 1900,
+                month = parseInt(value.substr(2, 2)),
+                day   = parseInt(value.substr(4, 2));
+            if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
+                return false;
+            }
+
+            // Validate the last check digit
+            return $.fn.bootstrapValidator.helpers.luhn(value);
+        },
+
+        /**
+         * Validate San Marino citizen number
+         *
+         * @see http://en.wikipedia.org/wiki/National_identification_number#San_Marino
+         * @param {String} value The ID
+         * @returns {Boolean}
+         */
+        _sm: function(value) {
+            return /^\d{5}$/.test(value);
         }
     };
 }(window.jQuery));

+ 3 - 9
src/js/validator/vat.js

@@ -146,9 +146,7 @@
                             month -= 20;
                         }
 
-                        try {
-                            var d = new Date(year, month, day);
-                        } catch (ex) {
+                        if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                             return false;
                         }
 
@@ -333,9 +331,7 @@
                     year += 100;
                 }
 
-                try {
-                    var d = new Date(year, month, day);
-                } catch (ex) {
+                if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                     return false;
                 }
 
@@ -846,9 +842,7 @@
                     year  = parseInt(value.substr(4, 2));
                 year = year + 1800 + parseInt(value.charAt(6)) * 100;
 
-                try {
-                    var d = new Date(year, month, day);
-                } catch (ex) {
+                if (!$.fn.bootstrapValidator.helpers.date(year, month, day)) {
                     return false;
                 }