|
|
@@ -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;
|
|
|
}
|
|
|
|