9
I need to format a mask for CNPJ. Until then this is done, but the standard of the company is to format with space instead of stitch.
This is the code I’m using.
valorDoTextBox = valorDoTextBox.replace(/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3")
Can someone explain to me how this part works (/^(\d{2})\.(\d{3})(\d)/, "$1.$2.$3")
so you can take the dots out and put a space.
thanks you can help me.
function MascaraParaLabel(valorDoTextBox) {
if (valorDoTextBox.length <= 14) {
//Coloca ponto entre o segundo e o terceiro dígitos
valorDoTextBox = valorDoTextBox.replace(/^(\d{2})(\d)/, "$1.$2")
//Coloca ponto entre o quinto e o sexto dígitos
valorDoTextBox = valorDoTextBox.replace(/^(\d{2})\.(\d{3})(\d)/, "$1 $2 $3")
//Coloca uma barra entre o oitavo e o nono dígitos
valorDoTextBox = valorDoTextBox.replace(/\.(\d{3})(\d)/, ".$1/$2")
//Coloca um hífen depois do bloco de quatro dígitos
valorDoTextBox = valorDoTextBox.replace(/(\d{4})(\d)/, "$1-$2")
}
return valorDoTextBox
I pass the value of the textbox without formatting 14397462000109 and the label that stands in front shows 14 397 462/0001-09 formatted in the enterprise standard.
I take the stitches but it didn’t work , and it’s all out of place.
– krispim
I pass the value of the textbox without formatting 14397462000109 and the label that stands in front shows 14 397 462/0001-09 formatted in the enterprise standard.
– krispim
Using this jsFiddle -> http://jsfiddle.net/jn8rpev0/ you can explain which steps are not working and how you want it to work?
– Sergio