Skip to content

Instantly share code, notes, and snippets.

@jadealombro
Last active August 1, 2021 16:13
Show Gist options
  • Save jadealombro/53e32bbfa2579e8d3848faf60e93223d to your computer and use it in GitHub Desktop.
Save jadealombro/53e32bbfa2579e8d3848faf60e93223d to your computer and use it in GitHub Desktop.
This code will restrict letters/alphabet from being typed in the WPForm's Phone field.
<?php
function restrict_letters_in_phone_field( ) {
?>
<script type="text/javascript">
;(function($) {
$('.wpforms-field-phone input').bind('input', function() {
var c = this.selectionStart,
r = /^[A-Za-z]+$/,
v = $(this).val();
if(r.test(v)) {
$(this).val(v.replace(r, ''));
c--;
}
this.setSelectionRange(c, c);
});
})(jQuery);
</script>
<?php
}
add_action( 'wpforms_wp_footer_end', 'restrict_letters_in_phone_field', 30 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment