Skip to content

Added RG validation #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ See: [Conferência de Inscrições Estaduais](http://www.sintegra.gov.br/insc_es

### RG ###

__Not implemented yet__
```javascript
var Brv = require('./br-validations');
var rg = '418757896';
var isValid = Brv.rg.validate(rg);
```

### PIS/PASEP ###

Expand Down
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ gulp.task('build', function(done) {
' ie: IE,',
' cpf: CPF,',
' cnpj: CNPJ,',
' pis: PIS',
' pis: PIS,',
' rg: RG',
' };',
'}));'].join('\n');

Expand Down
21 changes: 19 additions & 2 deletions releases/br-validations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* br-validations
* A library of validations applicable to several Brazilian data like I.E., CNPJ, CPF and others
* @version v0.2.4
* @version v0.3.0
* @link http://github.com/the-darc/br-validations
* @license MIT
*/
Expand Down Expand Up @@ -662,10 +662,27 @@ PIS.validate = function(pis) {
return Number(pisd) === calculateDigit(pisi);
};

var RG = {};

RG.validate = function(rg){
rg = rg.split('');
var vd;
var multiplier = 2;
var total = 0;

for (var i = 0; i < rg.length - 1; i++) {
total += rg[i] * multiplier;
multiplier += 1;
}

vd = 11 - total % 11;
return (parseInt(rg[rg.length - 1]) === vd);
};
return {
ie: IE,
cpf: CPF,
cnpj: CNPJ,
pis: PIS
pis: PIS,
rg: RG
};
}));
Loading