Skip to content

Instantly share code, notes, and snippets.

@attilabacso
Last active June 20, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attilabacso/03d6423601fb0818dc3b30ac1097d4fd to your computer and use it in GitHub Desktop.
Save attilabacso/03d6423601fb0818dc3b30ac1097d4fd to your computer and use it in GitHub Desktop.
Jquery Phone number restriction
// 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