Created
October 26, 2016 07:36
-
-
Save greathmaster/296a3053c56eaec7c762093633aecfdc to your computer and use it in GitHub Desktop.
Actively formats phone number into XXX-XXX-XXXX format
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
| //Actively formats phone number into XXX-XXX-XXXX format | |
| function format_phone_number() | |
| { | |
| //Adapted from: http://stackoverflow.com/questions/26412623/jquery-or-javascript-to-autoformat-phone-mask | |
| echo | |
| "<script> | |
| <!-- | |
| jQuery('#bphone').keyup(function(ev) { | |
| var key = ev.which; | |
| if (key < 48 || key > 57 || key != 45) { | |
| ev.preventDefault(); | |
| } | |
| if (this.value.length > 12) { | |
| this.value = this.value.slice(0, -1); | |
| return; | |
| } | |
| this.value = this.value.replace(/^(\d{3})(\d)/, '$1-$2').replace(/^(\d{3}-\d{3})(\d)/, '$1-$2'); | |
| }); | |
| --> | |
| </script>"; | |
| } | |
| add_action("pmpro_checkout_after_form", "format_phone_number"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment