Wednesday , 3 June 2015
Home » Helpful Tips and Tricks » [jQuery] Format Number to US Phone Format
[jQuery] Format Number to US Phone Format

[jQuery] Format Number to US Phone Format

Hello Friends,

I am working with one of the big “Hospital Management System” since last 3 weeks. I have got something to share with you guys. Even if it is small but tricky if your client needs such implementation. There are fields for phone number and cell numbers. Phone format in US is (000) 000 0000 and client want us to do it automatically once data entry people enter number as 0000000000. Here is jQuery script that does it automatically once you blur from the textbox.

  var val_field = jQuery(this).val();
  val_field = jQuery.trim(val_field);
  if(val_field.length == 10) {
    var val_field1 = val_field.substring(0,3);
    var val_field2 = val_field.substring(3,6);
    var val_field3 = val_field.substring(6);
    jQuery(this).val('('+val_field1+') '+val_field2+' '+val_field3);

Format Number to US Phone Format, Phone Number Format using jQuery, Automatically take US Phone Format using above code.

About Rakshit Patel

I am PHP Freelancer, Rakshit Patel AKA WordPress Freelancer working as PHP Programmer India. I am here to share all my developing knowledge, quick coding techniques, quick solutions to save your time and help you guys for any issue or bug fixing. If you have any PHP, WordPress, Magento related work, please contact me. I am interested for the work.

One comment

  1. Thanks for this information :-)

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>