Numbers in format of cpf (JS)

1

I get numbers from a cpf coming from the API, then it goes to a table that I did, except that the numbers are not in the format of cpf xxx.xxx.xxx-xx and I would like it to stay, but I do not know how . You just have to click on login and go to the site where you have the table, there the API will put the data that has in it the user, and it comes with cpf, but without correct format

    
asked by anonymous 14.12.2017 / 13:38

1 answer

3

You can use the Jquery Mask Plugin

$(document).ready(function(){
  $('.cpf').mask('000.000.000-00', {reverse: true});
});

link

Example:

$(function() {
    $('.cpf').mask('000.000.000-00', {reverse: true});
});
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script><scripttype="text/javascript" src="https://igorescobar.github.io/jQuery-Mask-Plugin/js/jquery.mask.min.js"></script><inputtype="text" class="cpf" id="cpf" maxlength="14">
    
14.12.2017 / 13:42