0
I have the following mask code using javascript regular expressions
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> simple document</title>
</head>
<body>
<center>
<form id="formulario">
<fieldset>
<legend>
Validação de formulário simples da XTi feito com expressões regulares
</legend>
<label for="cpf">CPF:</label>
<input name="cpf" type="text" maxlength="11" /><br />
<input type="button" value="validar();" />
</fieldset>
</form>
</center>
<script type="text/javascript">
var formulario = document.getElementById("formulario");
var cpf = formulario.cpf;
var re_cpf = /^([\d]{3})([\d]{3})([\d]{3})([\d]{2})$/;
cpf.onkeyup = function(){
cpf.value = cpf.value.replace(re_cpf, "$1.$2.$3-$4");
}
</script>
</body>
</html>
The problem is that the dots and the dash only appear after the person finishes typing, and not at the same time as she is typing, how could it solve this ?
See https://answall.com/q/278167/101
– Maniero
Change the line
cpf.value = cpf.value.replace(re_cpf, "$1.$2.$3-$4");
formascara(cpf);
and can also delete the linevar re_cpf = /^([\d]{3})([\d]{3})([\d]{3})([\d]{2})$/;
that will no longer serve.– Sam
The question you put on the Link did not solve the problem, Please remove the duplicate tag...
– Demetrius
@Demetrius explain why you haven’t solved.
– NoobSaibot
http://jsfiddle.net/h31ykrfj/
– NoobSaibot