Telephone number

My words (phone numbers) can have at the beginning of "00" or "+".

Example phone number:

00xxx xx xxxxxxx
+xxx xx xxxxxxx
(+xxx) xx xxxxxxx
(00xxx) xx xxxxxxx

I have:

Regex regexObj = new Regex(@"^\(?[+( ]?([0-9]{3})\)?[) ]?([0-9]{2})[- ]?([0-9]{7})$");

if (regexObj.IsMatch(TextBox1.Text))
{
    // IF OK
    string formattedPhoneNumber = regexObj.Replace(TextBox1.Text, "(+$1) $2 $3");
}

How to put it in regex? So far I can only put "+" and "(", ")"

thank

+3
source share
6 answers

how about this:

Regex regexObj = new Regex(@"^(?:\(?)(?:\+|0{2})([0-9]{3})\)? ([0-9]{2}) ([0-9]{7})$");

EDIT:

^(?:\((?:\+|00)([0-9]{3})\)|(?:\+|00)([0-9]{3}))? ([0-9]{2})[- ]?([0-9]{7})$
+1
source

4- , 2 , 7 .

(?:(00\d{3})|(\+\d{3})|(\(\+\d{3}\))|(\(00\d{3}\)))\s(\d{2})\s(\d{7})

+1

:

Regex regexObj = new Regex(@"^(?:(?:\+|00)([0-9]{3})|\((?:\+|00)([0-9]{3})\))[- ]?([0-9]{2})[- ]?([0-9]{7})$");

if (regexObj.IsMatch(TextBox1.Text))
{
    //IF OK
    string formattedPhoneNumber = regexObj.Replace(TextBox1.Text, "(+$1$2) $3 $4");
}

:

(?:\+|00): + 00 -

(?:(?:\+|00)([0-9]{3})|\((?:\+|00)([0-9]{3})\)): + xxx 00xxx (+ xxx) (00xxx), . ( ) , , , (.. (+999 99 9999999 .

"(+$1$2) $3 $4": , ([0-9] {3}) , - .

+1

.

+353, 00 353, 011 353, +353 (0), 00 353 (0), 011 353 (0) 0, .

  Pattern: ^(\(?(?:0(?:0|11)\)?[\s-]?\(?|\+)(353)\)?[\s-]?)?\(?0?(?:\)[\s-]?)?([1-9]\d{1,4}\)?[\d\s-]+)((?:x|ext\.?|\#)\d{3,4})?$

, "353" $2, , , , $2 .

$4 .

NSN ( , ) $3.

, RegEx NSN .

Don't worry about users entering inconsistent brackets or random punctuation. The goal is for the user to enter the correct number of digits to make a valid phone number. Retrieve and confirm this number, then clear it for display using the correct formatting rules for each range of numbers.

+1
source

All Articles