Numbers in Cpf (JS) format

Asked

Viewed 265 times

1

I get numbers from a Cpf coming from the API, then it goes to a table that I made, only the numbers are not in Cpf xxx.xxx.xxx-xx format and I would like it to stay, but I don’t know how. Just click on login and go to the site where you have the table, there the API will put the data that has in it user, and it comes together Cpf, but no correct format

1 answer

3


You can use the Jquery Mask Plugin

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

https://igorescobar.github.io/jQuery-Mask-Plugin/

Example:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.