0 Replies - 1618 Views - Last Post: 22 November 2007 - 05:59 AM

#1 girasquid   User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Formatting a ten-digit phone number

Posted 22 November 2007 - 05:59 AM

Description: Just pass your ten-digit number to the sub, and store the output. Tested and working with 4631189780,463-118-8732,(579).293-3763,(560) 879.3873. To adjust the way that the number is formatted, change the way that $formated is set up($1,$2,and $3 are the individual 'chunks' of the phone number).This snippet takes a ten-digit phone number and formats it, in the form (xxx) xxx.xxxx.
sub formatPhoneNumber {
	my $number = shift;
	die "$number is not a valid 10-digit phone number" unless $number =~ /^(?([1-9]d{2}))?[-., ]*?([1-9]d{2})[-., ]*?(d{4})$/;
	my $formatted = "($1) $2.$3";
	return $formatted;
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1