Title: Incomplete and incorrect.
Name: g1smd
Date: 10/27/2012 1:44:28 PM
Comment:
For purely landline 01 & 02 and mobile 07 try this: ^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(1(?:\d{4}\)?[\s-]?\d{4,5}|\d{3}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{2}\)?[\s-]?\d{3}[\s-]?\d{3,4})|2\d\)?[\s-]?\d{4}[\s-]?\d{4}|7\d{3}[\s-]?\d{3}[\s-]?\d{3})(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$ OR use the pattern in http://www.regexlib.com/REDetails.aspx?regexp_id=3606 to validate the format, the pattern in http://www.regexlib.com/REDetails.aspx?regexp_id=3607 to extract the NSN, then simply check that the NSN begins 1, 2 or 7.
Title: Incomplete and incorrect.
Name: g1smd
Date: 10/27/2012 1:43:02 PM
Comment:
^((\(44\))( )?|(\(\+44\))( )?|(\+44)( )?|(44)( )?)?((0)|(\(0\)))?( )?(((1[0-9]{3})|(7[1-9]{1}[0-9]{2})|(20)( )?[7-8]{1})( )?([0-9]{3}[ -]?[0-9]{3})|(2[0-9]{2}( )?[0-9]{3}[ -]?[0-9]{4}))$ This pattern is very inefficient and fails to match many valid UK number formats. Many of the brackets are redundant. The (\(44\)) simplifies to \(44\) for example and ( )? should be \s? too. The (\(44\))( )?|(\(\+44\))( )? 'OR' construct simplifies to \(\+?44\)\s? for example, and the (\+44)( )?|(44)( )?) 'OR' construct simplifies to \+?44\s? too. The [1-9]{1} should be just [1-9]. The literal (20) does not need to be in brackets. The [7-8] should be [78] but note that London numbers also begin with 3 now. Your London pattern fails in other ways too. It expects 20 7 XXX XXX which is also a digit short of reality and in a completely incorrect format. There is no need for a London pattern. You need a pattern for all 02 numbers. 02 area codes use the 2+8 format but your final chunk of code expects all 02 area codes to be in 3+7 format. Your pattern also fails to match valid UK numbers in the real 3+7, 4+5, 5+5 and 5+4 formats. I could condemn this RegEx in many other ways, but I fear I will run out of space in this comment box. For the correct pattern for all of the UK numbers try ^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{5}\)?[\s-]?\d{4,5}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{3}\)? [\s-]?\d{3}[\s-]?\d{3,4}|\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$ which allows every UK format as well as catering for extensions. See also http://www.regexlib.com/REDetails.aspx?regexp_id=3606
For purely landline 01 & 02 and mobile 07 try this: ^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(1(?:\d{4}\)?[\s-]?\d{4,5}|\d{3}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{2}\)?[\s-]?\d{3}[\s-]?\d{3,4})|2\d\)?[\s-]?\d{4}[\s-]?\d{4}|7\d{3}[\s-]?\d{3}[\s-]?\d{3})(?:(?:[\s-]?(?:x|ex
Title: Incomplete and incorrect.
Name: g1smd
Date: 10/27/2012 1:39:56 PM
Comment:
^((\(44\))( )?|(\(\+44\))( )?|(\+44)( )?|(44)( )?)?((0)|(\(0\)))?( )?(((1[0-9]{3})|(7[1-9]{1}[0-9]{2})|(20)( )?[7-8]{1})( )?([0-9]{3}[ -]?[0-9]{3})|(2[0-9]{2}( )?[0-9]{3}[ -]?[0-9]{4}))$ This pattern is very inefficient and fails to match many valid UK number formats. Many of the brackets are redundant. The (\(44\)) simplies to \(44\) for example and ( )? should be \s? too. The (\(44\))( )?|(\(\+44\))( )? 'OR' construct simplies to \(\+?44\)\s? for example, and the (\+44)( )?|(44)( )?) 'OR' construct simplifies to \+?44\s? too. The [1-9]{1} should be just [1-9]. The literal (20) does not need to be in brackets. The [7-8] should be [78] but note that London numbers also begin with 3 now. Your London pattern fails in other ways too. It expects 20 7 XXX XXX which is also a digit short of reality and in a completely incorrect format. There is no need for a London pattern. You need a pattern for all 02 numbers. 02 area codes use the 2+8 format but your final chunk of code expects all 02 area codes to be in 3+7 format. Your pattern also fails to match valid UK numbers in the real 3+7, 4+5, 5+5 and 5+4 formats. I could condemn this RegEx in many other ways, but I fear I will run out of space in this comment box. For the correct pattern for all of the UK numbers try ^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{5}\)?[\s-]?\d{4,5}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{3}\)? [\s-]?\d{3}[\s-]?\d{3,4}|\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$ which allows every UK format as well as catering for extensions. See also http://www.regexlib.com/REDetails.aspx?regexp_id=3606
For purely landline 01 & 02 and mobile 07 try this: ^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(1(?:\d{4}\)?[\s-]?\d{4,5}|\d{3}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{2}\)?[\s-]?\d{3}[\s-]?\d{3,4})|2\d\)?[\s-]?\d{4}[\s-]?\d{4}|7\d{3}[\s-]?\d{3}[\s-]?\d{3})(?:(?:[\s-]?(?:x|ext\.?
Title: Nigel
Name: [email protected]
Date: 7/8/2012 3:08:20 PM
Comment:
[1-9]{1} simplifies to [1-9] and
[7-8]{1} simplifies to [7-8]
All 02 area codes are 02x xxxx xxxx format.
The pattern doesn't appear cater for UK 3+7, 4+5, 5+5 or 5+4 formats.
Title: Amended
Name: Antony Kennedy
Date: 6/30/2010 9:36:24 AM
Comment:
I've amended this for London numbers, and other fixes.
Title: Doesn't match 020 8123 4567
Name: Dave
Date: 4/9/2010 6:42:08 PM
Comment:
The correct way to write London numbers is 020 xxxx xxxx. Your regex doesn;t cope with this.