Hi,

I've this script that takes care of picking phone number in standard format - xxx-xxxx, further i would like it to pick phonenumber even without hypen - xxxxxxx. How can i do that?

foreach $number (@numbers)
{
if ($number =~ m/(^\d{3}-\d{4}$)/)
{
push @results, $number;
}
}

Thanks, Prince

Hi,

I've this script that takes care of picking phone number in standard format - xxx-xxxx, further i would like it to pick phonenumber even without hypen - xxxxxxx. How can i do that?

foreach $number (@numbers)
{
if ($number =~ m/(^\d{3}-\d{4}$)/)
{
push @results, $number;
}
}

Thanks, Prince

It is simple.I understood that you need to match both telephone numbers format such as xxx-xxxx and xxxxxxx.The following script will do the job for you.

foreach $number (@numbers)
      {
      if ($number =~ m/(^\d{3}-\d{4}$)/ || $number=~/(^\d{7}$)/)
      {
      push @results, $number;
      }
      }

Use opional metacharacter ?

if ($number =~ m/^(\d{3}-?\d{4})$/)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.