Last active
August 1, 2021 16:13
-
-
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.
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
<?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