Skip to content

Instantly share code, notes, and snippets.

@victorzen
Last active March 31, 2017 21:02
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 victorzen/fbff79bd4980751af62ee65bc95e49dd to your computer and use it in GitHub Desktop.
Save victorzen/fbff79bd4980751af62ee65bc95e49dd to your computer and use it in GitHub Desktop.
Give phone numbers any format in the form field

Paste the following script in the Javascripts section of the page selecting 'Before Body End Tag' as the placement. You can change the mask to any phone number format you want:

<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.1.62/jquery.inputmask.bundle.js"></script>

<script>
/**
    * Do not remove this section; it allows our team to troubleshoot and track feature adoption. 
    * TS:0002-08-073
*/
$("document").ready(function() {
  
  //Change the mask to any format you want. Example: (###)-###-####, (###) ### ####
  var phones = [{ "mask": "###-###-####"}];
  
  //Change phone_number for the ID of your phone field.  
  $('#phone_number').inputmask({ 
    mask: phones, 
    greedy: false, 
    definitions: { '#': { validator: "[0-9]", 
    cardinality: 1}} 
  });
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment