ソースを参照

fixed Russian VAT validation

Igor Stepin 11 年 前
コミット
1de39ee6f7
2 ファイル変更24 行追加2 行削除
  1. 2 2
      src/js/validator/vat.js
  2. 22 0
      test/spec/validator/vat.js

+ 2 - 2
src/js/validator/vat.js

@@ -1216,10 +1216,10 @@
          * @returns {Boolean}
          */
         _ru: function(value) {
-            if (/^RU([0-9]{9}|[0-9]{12})$/.test(value)) {
+            if (/^RU([0-9]{10}|[0-9]{12})$/.test(value)) {
                 value = value.substr(2);
             }
-            if (!/^([0-9]{9}|[0-9]{12})$/.test(value)) {
+            if (!/^([0-9]{10}|[0-9]{12})$/.test(value)) {
                 return false;
             }
 

+ 22 - 0
test/spec/validator/vat.js

@@ -656,6 +656,28 @@ describe('vat', function() {
         }
     });
 
+    it('Russian VAT number', function() {
+        this.bv.updateOption('vat', 'vat', 'country', 'RU');
+
+        // Valid samples
+        var validSamples = ['RU7805145876', 'RU781300557475', '7805145876', '781300557475'];
+        for (var i in validSamples) {
+            this.bv.resetForm();
+            this.$vat.val(validSamples[i]);
+            this.bv.validate();
+            expect(this.bv.isValid()).toBeTruthy();
+        }
+
+        // Invalid samples
+        var invalidSamples = ['RU7805145877', 'RU781300557474', '7805145877', '781300557474'];
+        for (i in invalidSamples) {
+            this.bv.resetForm();
+            this.$vat.val(invalidSamples[i]);
+            this.bv.validate();
+            expect(this.bv.isValid()).toEqual(false);
+        }
+    });
+
     it('Swedish VAT number', function() {
         this.bv.updateOption('vat', 'vat', 'country', 'SE');