[Pdx-pm] regex & phone numbers...
karic at lclark.edu
Thu Jul 25 12:23:08 CDT 2002
Now that all that madness is past... I've got another regex stumper.
I want to clean up phone numbers that people submit in a form. They
could come in all kinds of ways, like...
503 123 4567
503-123-4567 ext. 89
123-4567 ext. 89
I want to convert the actual seven- or ten-digit phone number part to
just xxx-xxx-xxxx. I also want to leave alone anything that comes
after that - which is obviously the tough part. The logic should be
basically this: just process through the number left to right,
grabbing the first seven or ten numbers, then reformat those and tack
on whatever's left. The challenge is figuring out when it's a
seven-digit or a ten-digit number.
I've conceptualized any number of highly complex and idiotic ways of
doing this. I'm just wondering if there's a simpler regex approach to
this... Any ideas?
More information about the Pdx-pm-list