Solved

# Regular Expression FAKE Phone Number handling

Posted on 2007-10-15

I've got a somewhat complex phone number regular expression i need made. I have a TextBox control on a form which gets validated using javascript regular expressions. I use .NET, and so I am using field validators and don't actually have access to the input programatically at the validator level. simply put, i must validate the input using a regular expression.

The phone number field accepts phone numbers, in a number of formats, such as:

9205551212

920-555-1212

(920) 555-1212

etc...

Here is the regular expression I already use to get the above results:

^\s*([\(]?)\[?\s*\d{3}\s*\]?[\)]?\s*[\-]?[\.]?\s*\d{3}\s*[\-]?[\.]?\s*\d{4}$

Simply put, there must always be 10 numbers, however, there may or may not be some separators in the number.

Now, something that is commonly happening is that I am getting junk input (fake phone numbers) put in by users. There are a few common paterns which they will use:

1) All 10 digits same number: 1111111111 OR 2222222222 OR etc...

2) Repeating pattern type 1: 1212121212 OR 2323232323 OR etc...

3) Repeating pattern type 2: 1231231231 OR 3213213213 OR etc...

4) Incrementing numbers: 1234567890 OR 0123456789

I would like to create a NEW Regular Expression that would work with javascript and only accept numbers which do NOT match any of the 4 types of common patterns above. This NEW expression, should not be built into my already current expression above which validates the "Format" of the number.

Can someone help?