Re: regex matching exactly 10 digits



jtbutler78@xxxxxxxxxxx wrote:
I am having an issue trying to match exactly 10 digits. I want to
append a '1' in front of 10 digit fax numbers. Numbers longer than 10
digits leave alone. I am using \d{10,10} match at least and at most 10
digits but it still appends a 1 to international numbers. I am missing
something but I am not sure what.

#strip out unneeded chars
$fax_num =~ s/[\s()-]//g;

#append 1 to 10 digit fax number
$fax_num =~ s/(\d{10,10})/1$1/;

It looks like that instead of appending a '1' you really want to prepend a
'1'. You could do it like this:

$fax_num = "1$fax_num" if $fax_num =~ tr/0-9// == 10;



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.



Relevant Pages