-3
My field that carries Cpf is this:
<div class="form-group">
@Html.LabelFor(model => model.cpf, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.cpf, new { htmlAttributes = new { @class = "form-control", @id = "cpf" } })
@Html.ValidationMessageFor(model => model.cpf, "", new { @class = "text-danger" })
</div>
</div>
and the button submit
I call the function
in the click:
<input type="submit" value="Create" class="btn btn-default" onclick="replaceCpf();"/>
My function js:
function replaceCPF(cpf) {
return cpf.replace(/^(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
}
How can the Cpf parameter?
onclick="replaceCpf(document.getElementById("cpf").value);"
?– Matheus Miranda
You don’t need the
@id = "cpf"
, may delete. Themodel.cpf
generates the id.– Matheus Miranda