ng-cpf-cnpj

1.0.1 • Public • Published

ng-cpf-cnpj

AngularJS directive to validate CPF/CNPJ numbers, using cpf_cnpj.js.

Build Status npm version

Instalation

npm install ng-cpf-cnpj cpf_cnpj --save

And add to your index.html

<script src="node_modules/cpf_cnpj/build/cpf_cnpj.min.js"></script>
<script src="node_modules/ng-cpf-cnpj/dist/index.min.js"></script>

And inject it to your angular.module

angular.module('myApp', ['ngCpfCnpj']);

Usage

Just add ng-cpf or ng-cnpj to any <input/>.

<form name="myForm">
 
  <input name="cpf" ng-model="cpf" ng-cpf />
  myForm.cpf.$valid: {{ myForm.cpf.$valid }}
 
  <input name="cnpj" ng-model="cnpj" ng-cnpj />
  myForm.cnpj.$valid: {{ myForm.cnpj.$valid }}
 
</form>

You can also use ui-mask, from ui-utils, to restrict the format:

<form name="myForm">
 
  <input name="cpf" ng-model="cpf" ng-cpf ui-mask="999.999.999-99" />
  myForm.cpf.$valid: {{ myForm.cpf.$valid }}
 
  <input name="cnpj" ng-model="cnpj" ng-cnpj ui-mask="99.999.999/9999-99" />
  myForm.cnpj.$valid: {{ myForm.cnpj.$valid }}
 
</form>

Copyright and License

Copyright (c) 2017 Marcel de Oliveira Coelho under the MIT license. Go Crazy. 🚀

Package Sidebar

Install

npm i ng-cpf-cnpj

Weekly Downloads

50

Version

1.0.1

License

MIT

Last publish

Collaborators

  • husscode