I need a regular expression that I can use in VBScript and .NET that will return only the numbers that are found in a string.
For Example any of the following \"str
Note: you've only solved half the problem here.
For US phone numbers entered "in the wild", you may have:
You'll need to add some smarts to your code to conform the resulting list of digits to a single standard that you actually search against in your database.
Some simple things you could do to fix this:
Before the RegEx removal of non-digits, see if there's an "x" in the string. If there is, chop everything off after it (will handle most versions of writing an extension number).
For any number with 10+ digits beginning with a "1", chop off the 1. It's not part of the area code, US area codes start in the 2xx range.
For any number still exceeding 10 digits, assume the remainder is an extension of some sort, and chop it off.
Do your database search using an "ends-with" pattern search (SELECT * FROM mytable WHERE phonenumber LIKE 'blah%'). This will handle sitations (although with the possibility of error) where the area code is not provided, but your database has the number with the area code.