3
I am creating a Web system and in this system there is the phone field, in this phone field, the user can put an 0800 or else a standard conventional phone DDD-Suffix-Prefix.
Even all right, I managed to create with a if
, only that when typing the second number it changes the mask if it is of the chosen pattern, then in case I wanted to hold the pattern only for the first character.
Below is the code I created.
<input type="text" id="telefone"
name="escTelefone"
class="medio"
placeholder="(99)1111-1111" maxlength="13" />
<!--pattern="\([0-9]{2}\)[0-9]{4}-[0-9]{4}"-->
<script type="text/javascript">
$("#telefone").keypress(function (event) {
if(event.keyCode == 48 ) {
$("#telefone").mask("0000-000-0000");
} else {
$("#telefone").mask("(00)0000-0000");
}
});
</script>