Created
May 17, 2016 18:01
-
-
Save phsantiago/3b0c8bf97df1b557bc602b393839fa7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#inputID').on('input',function(){ | |
if($(this).val().indexOf('-')!=-1){ | |
if($(this).val().length==15){ | |
var _value = $(this).val(); | |
_value = _value.split(''); | |
var iTraco = _value.indexOf('-'); | |
var letterAfter = _value[iTraco+1]; | |
_value[iTraco] = letterAfter; | |
_value[iTraco+1] = '-'; | |
_value = _value.join(''); | |
$(this).unmask('(99) 9999-99999') | |
$(this).mask('(99) 99999-9999'); | |
$(this).val(_value); | |
}else if($(this).val().length==14){ | |
$(this).unmask(); | |
$(this).mask('(99) 9999-99999'); | |
this.selectionStart = this.selectionEnd = this.value.length; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment