I'm creating a web system and in this system there is the phone field, in this phone field, the user can put a 0800 or a conventional standard phone DDD-Suffix-Prefix.
It's okay, I was able to create it with a if
, but when typing the second number it changes the mask if it is of the chosen pattern, so 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>