Created
February 9, 2025 12:38
-
-
Save Qubadi/5fc5f75bdccfb52c364c1bbf70d7cbbe to your computer and use it in GitHub Desktop.
Jetformbuilder: Phone number fix, only allow numbers in tel fields
This file contains hidden or 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
We have developed a code for telephone input numbers, where it only allows users to type in numbers. | |
On phones and tablets, it automatically shows the number keyboard when you try to type in the field, | |
instead of the full keyboard. | |
By using the Set Input Mask option, you can restrict input to numbers. However, on phones and tablets, | |
the full keyboard still appears when trying to enter a value in a telephone input field. Normally, | |
it should only display the number keyboard instead of the full keyboard. | |
In JetFormBuilder, this does not work as expected by default. When a telephone input is selected, | |
it should trigger the number keyboard, but it doesn't. | |
Copy the following JScode and create a JS snippet using your snippet plugins. | |
Paste the code into the plugin and save it. | |
________________________ | |
jQuery(document).ready(function($) { | |
$('input[type="tel"].jet-form-builder__field').on('input', function() { | |
// Remove non-numeric characters except "+" for international numbers | |
let sanitizedValue = $(this).val().replace(/[^0-9+]/g, ''); | |
// Ensure "+" is only at the beginning (if needed) | |
if (sanitizedValue.includes("+") && sanitizedValue.indexOf("+") !== 0) { | |
sanitizedValue = sanitizedValue.replace(/\+/g, ""); | |
sanitizedValue = "+" + sanitizedValue; | |
} | |
$(this).val(sanitizedValue); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment