House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  Regular Expressions (RegEx)

How to clean a phone number with regex

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Michael Grove
02/25/2009 03:45 PM

I am very new to regex and I basically need to clean a phone number. I need all numbers entered to look like 5555555555. I am using REReplace(foo.foo, "[^0-9]", "", "ALL") and it is cleaning 555-555-5555 but not (555)444 4444. Any help would be greatly appreciated. THX

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
02/26/2009 02:40 AM

> I am very new to regex and I basically need to clean a phone number. I need all numbers entered to look like 5555555555. I am using REReplace(foo.foo, "[^0-9]", "", "ALL") and it is cleaning 555-555-5555 but not (555)444 4444. There's no reason that shouldn't work. Doing rereplace(input,'[^0-9]','','all') will replace everything that is not 0123456789 with blank. You could also try doing rereplace(input,'\D','','all') which will have the same effect ( \D is the opposite of \d and \d is shorthand for [0-9] ). I suspect maybe some other part of your code is interfering with the results in some way.


<< Previous Thread Today's Threads Next Thread >>

Search regex

May 22, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference