[jQuery] Format Number to US Phone Format

jqury-ui-developer

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.

jQuery("#v_cell").blur(function(){
  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.

1 Comments on [jQuery] Format Number to US Phone Format

  • James Abuda
    May 30, 2013 at 8:14 am

    Thanks for this information :-)

Leave a Reply

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

Sponsors

Sponsors

Recommended

DHgate Computers
DHgate.com - Computers, Cell Phones & more
  • We find everbuying built in php and use css to control the style.

About Author

PHP Freelancer

PHP Freelancer I am PHP Freelancer
PHP Freelancer
, Rakshit Patel working as PHP Programmer India. I am here to share all my developing knowledge with you people. For Hire PHP Developer India, contact me.
Follow on twitter: @raxit4u2

Get Free Programming Tutorials:

Become a Fan

Popular Topics

Recent Posts

Most Popular

Recent Comments

Get a Free Quote
$
$
$
Security Question: 3 + 8 = ?
$