UNPKG

br-validations

Version:

A library of validations applicable to several Brazilian data like I.E., CNPJ, CPF and others

27 lines (24 loc) 673 B
var IE = function(uf) { if (!(this instanceof IE)) { return new IE(uf); } this.rules = IErules[uf] || []; this.rule; IE.prototype._defineRule = function(value) { this.rule = undefined; for (var r = 0; r < this.rules.length && this.rule === undefined; r++) { var str = value.replace(/[^\d]/g,''); var ruleCandidate = this.rules[r]; if (str.length === ruleCandidate.chars && (!ruleCandidate.match || ruleCandidate.match.test(value))) { this.rule = ruleCandidate; } } return !!this.rule; }; IE.prototype.validate = function(value) { if (!value || !this._defineRule(value)) { return false; } return this.rule.validate(value); }; };