Sha256: 2d362ee8d4f8e2222389a111c79f48a2ae3c71c1e445987c19d10dc7b408e53c

Contents?: true

Size: 1.24 KB

Versions: 48

Compression:

Stored size: 1.24 KB

Contents

var composed, cpfable, stampit;

stampit = require('../../../vendor/stampit');

cpfable = stampit({
  validate_format: function(value) {
    var c, d1, dv, i, v, _i, _j;

    value = value.replace(/[\.\-]/g, "");
    if (value.length < 11) {
      return false;
    }
    if (value.match(/^(0+|1+|2+|3+|4+|5+|6+|7+|8+|9+)$/)) {
      return false;
    }
    c = value.substr(0, 9);
    dv = value.substr(9, 2);
    d1 = 0;
    v = false;
    i = 0;
    for (i = _i = 0; _i <= 9; i = ++_i) {
      d1 += c.charAt(i) * (10 - i);
    }
    if (d1 === 0) {
      return false;
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) {
      d1 = 0;
    }
    if (+dv.charAt(0) !== d1) {
      return false;
    }
    d1 *= 2;
    for (i = _j = 0; _j <= 9; i = ++_j) {
      d1 += c.charAt(i) * (11 - i);
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) {
      d1 = 0;
    }
    if (+dv.charAt(1) !== d1) {
      return false;
    }
    return true;
  },
  validate_each: function(record, attribute, value) {
    if (value && !this.validate_format(value)) {
      return record.errors.add(attribute, 'cpf', this.options);
    }
  }
});

composed = stampit.compose(require('./validatorable'), cpfable);

composed.definition_key = 'validates_cpf_format';

module.exports = composed;

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
ende-0.5.22 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.21 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.20 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.19 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.18 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.17 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.16 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.15 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.14 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.13 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.12 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.10 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.9 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.8 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.7 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.6 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.4.25 vendor/components/indefinido-indemma/lib/record/validations/cpf.js
ende-0.5.5 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.4 components/indefinido/indemma/master/lib/record/validations/cpf.js
ende-0.5.3 components/indefinido/indemma/master/lib/record/validations/cpf.js