Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

[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.


1 Comment

Leave a Reply

Your email address will not be published.