Last active
June 20, 2017 16:51
-
-
Save attilabacso/03d6423601fb0818dc3b30ac1097d4fd to your computer and use it in GitHub Desktop.
Jquery Phone number restriction
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
// Phone number restriction for input_10_4 field | |
// Start with + character | |
$('#input_10_4').val('+'); | |
$('#input_10_4').attr('data-initial', '+'); | |
// Cannot delete the + character | |
$("#input_10_4").on("keyup", function() { | |
var value = $(this).val(); | |
$(this).val($(this).data("initial") + value.substring(1)); | |
}); | |
// Enter only numeric characters | |
$("#input_10_4").on("keypress", function(event) { | |
if (event.charCode < 48 || event.charCode > 57) {return false;} //keyCode is not working on Firefox | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment