Browse Source

Fixed Chilean ID (RUT/RUN) finished in 'K' or 'k'.

Marcelo Ampuero 11 years ago
parent
commit
a784242a05
2 changed files with 6 additions and 4 deletions
  1. 3 3
      src/js/validator/id.js
  2. 3 1
      test/spec/validator/id.js

+ 3 - 3
src/js/validator/id.js

@@ -293,10 +293,10 @@
          * @returns {Boolean}
          * @returns {Boolean}
          */
          */
         _cl: function(value) {
         _cl: function(value) {
-            if (!/^\d{7,8}[-]{0,1}[0-9K]$/.test(value)) {
+            if (!/^\d{7,8}[-]{0,1}[0-9K]$/i.test(value)) {
                 return false;
                 return false;
             }
             }
-            value = value.replace(/\D/g, '');
+            value = value.replace(/\-/g, '');
             while (value.length < 9) {
             while (value.length < 9) {
                 value = '0' + value;
                 value = '0' + value;
             }
             }
@@ -311,7 +311,7 @@
             } else if (sum === 10) {
             } else if (sum === 10) {
                 sum = 'K';
                 sum = 'K';
             }
             }
-            return sum + '' === value.charAt(8);
+            return sum + '' === value.charAt(8).toUpperCase();
         },
         },
 
 
         /**
         /**

+ 3 - 1
test/spec/validator/id.js

@@ -128,8 +128,10 @@ describe('id', function() {
     it('Chilean national identification number (RUN/RUT)', function() {
     it('Chilean national identification number (RUN/RUT)', function() {
         this.bv.updateOption('id', 'id', 'country', 'CL');
         this.bv.updateOption('id', 'id', 'country', 'CL');
 
 
+        console.log('Chilean ruts');
+
         // Valid samples
         // Valid samples
-        var validSamples = ['76086428-5', '22060449-7', '12531909-2'];
+        var validSamples = ['76086428-5', '22060449-7', '12531909-2','12937893-K','12937893-k'];
         for (var i in validSamples) {
         for (var i in validSamples) {
             this.bv.resetForm();
             this.bv.resetForm();
             this.$id.val(validSamples[i]);
             this.$id.val(validSamples[i]);