|
|
@@ -1798,6 +1798,82 @@
|
|
|
};
|
|
|
}(window.jQuery));
|
|
|
;(function($) {
|
|
|
+ $.fn.bootstrapValidator.validators.id = {
|
|
|
+ html5Attributes: {
|
|
|
+ message: 'message',
|
|
|
+ country: 'country'
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Validate identification number in different countries
|
|
|
+ *
|
|
|
+ * @param {BootstrapValidator} validator The validator plugin instance
|
|
|
+ * @param {jQuery} $field Field element
|
|
|
+ * @param {Object} options Consist of key:
|
|
|
+ * - message: The invalid message
|
|
|
+ * - country: The ISO 3166-1 country code
|
|
|
+ * @returns {Boolean}
|
|
|
+ */
|
|
|
+ validate: function(validator, $field, options) {
|
|
|
+ var value = $field.val();
|
|
|
+ if (value == '') {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ var country = options.country || value.substr(0, 2),
|
|
|
+ method = ['_', country.toLowerCase()].join('');
|
|
|
+ if (this[method] && 'function' == typeof this[method]) {
|
|
|
+ return this[method](value);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Validate Brazilian ID (CFP)
|
|
|
+ * Examples:
|
|
|
+ * - Valid: 39053344705, 390.533.447-05, 111.444.777-35
|
|
|
+ * - Invalid: 231.002.999-00
|
|
|
+ *
|
|
|
+ * @see http://en.wikipedia.org/wiki/Cadastro_de_Pessoas_F%C3%ADsicas
|
|
|
+ * @param {String} value The ID
|
|
|
+ * @returns {Boolean}
|
|
|
+ */
|
|
|
+ _br: function(value) {
|
|
|
+ if (/^1{11}|2{11}|3{11}|4{11}|5{11}|6{11}|7{11}|8{11}|9{11}|0{11}$/.test(value)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!/^\d{11}$/.test(value) && !/^\d{3}\.\d{3}\.\d{3}-\d{2}$/.test(value)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ value = value.replace(/\./g, '').replace(/-/g, '');
|
|
|
+
|
|
|
+ var d1 = 0;
|
|
|
+ for (var i = 0; i < 9; i++) {
|
|
|
+ d1 += (10 - i) * parseInt(value.charAt(i));
|
|
|
+ }
|
|
|
+ d1 = 11 - d1 % 11;
|
|
|
+ if (d1 == 10 || d1 == 11) {
|
|
|
+ d1 = 0;
|
|
|
+ }
|
|
|
+ if (d1 != value.charAt(9)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var d2 = 0;
|
|
|
+ for (i = 0; i < 10; i++) {
|
|
|
+ d2 += (11 - i) * parseInt(value.charAt(i));
|
|
|
+ }
|
|
|
+ d2 = 11 - d2 % 11;
|
|
|
+ if (d2 == 10 || d2 == 11) {
|
|
|
+ d2 = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return (d2 == value.charAt(10));
|
|
|
+ }
|
|
|
+ };
|
|
|
+}(window.jQuery));
|
|
|
+;(function($) {
|
|
|
$.fn.bootstrapValidator.validators.identical = {
|
|
|
html5Attributes: {
|
|
|
message: 'message',
|