Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Formatting Phone Numbers in the Invoice Page


finjay

Recommended Posts

How can I format phone numbers to be the same on invoices? Right now it's whatever a person enters. I'd prefer it to be (123) 456-7899

instead of 1234567899 or 123.456.7899 or whatever a customer enters.

Link to comment
Share on other sites

I doodled a function to format the phone number:

 

////
//
 function fmt_phone($pn) {
$result= '';

// cleanse the input of all non-numeric entries

for ( $i = 0; $i < strlen($pn); $i++ ) {
 if ( strstr('0123456789', substr($pn,$i,1) )  ) {
   $result .= substr($pn,$i,1);
 }
}

// ideal result

if ( strlen( $result ) == 10 ) {
  return '('. substr($result,0,3) . ') ' . substr($result,3,3) . '-' . substr($result,6,4);
} else {
  $i = strlen($result);

// less than ideal result

  if ( $i == 7 ) {
	return substr($result,$i-7,3) . '-' . substr($result,$i-4,4);
  } else {

// default result

	return $result;
  }
}
 }

I'm just not sure where you want it?

:unsure:

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...