Sunday, May 10, 2009

To "9" or not to "9", that is the question

I know, terrible title....

Anyway I have a quick post today about normalizing numbers with a "9" prefix (or without) using one line rather than two rules. This tip comes from Mike Stacy.

....edited on May 28, 2009....

I've come across a nasty case where the MOC client normalizes the number but just doesn't want to dial it. I originally posted the fact that you could use a "?" following a number such as "9" so the input of that value is optional. As it turns out, this isn't the case.

The following format does work:

^(?:91|9|1|)(780\d{7})$
$1

This will normalize the following numbers:

97805551212
17805551212
7805551212

...all into the following:

7805551212

No need to create two rules to handle the 9, 1 or nothing in front of your numerical value.

Cheers!

No comments:

Post a Comment