2016-01-04 2 views
-1

Какое регулярное выражение для бесплатного бесплатного номера США 1 800 ###-####? Как проверить это для телефона с помощью C#?Регулярное выражение для бесплатного бесплатного номера в США

+0

, что вы пытались до сих пор? – GottZ

+0

на самом деле я не могу сделать регулярное выражение. –

+0

вам следует начать обучение регулярному выражению. у него есть причины, по которым люди платят за такие вещи. кроме того, данное решение Мохита действительно работает. – GottZ

ответ

1

Вы можете попробовать это

^(\+?1)?(8(00|44|55|66|77|88)[2-9]\d{6})$ 

Объяснение

^ - indicates the beginning of a regular expression (required); 
(- indicates the beginning of a regular expression block - 
    blocks are important to define inner expressions so they can be referenced by the variables $1, $2, $3, etc; 
\+1|1? - indicates optional digits '+1' or '1' (the ? sign defines the literal as optional); 
) - closes the block; 
8 - matches the literal '8'; 
(- another block starting; 
00|55|66|77|88 - matches 00 or 55 or 66 or 77 or 88 (you guessed right, the | sign is the OR operator); 
) - closes the inner block; 
[2-9] - matches one digit in the range from 2 to 9 (2, 3, 4, 5, 6, 7, 8 and 9), 
    and as you also guessed the [] pair of brackets encloses a range; 
    other range examples: [0-9] matches 0 to 9; [a-z] matches a, b, c, ...z); 
\d - matches any valid digit (same as [0-9]); 
{6} - defines the number of occurrences for the previous expression, 
    i.e. exactly 6 digits in the range 0-9. This can also contain a variable number of occurrences, 
    for example to match a sequence of 6 to 9 digits: {6,9}; 
    or to match at least 6 with no maximum: {6,}; 
) - closes the other block; 
$ - indicates the end of the regular expression (required); 
+0

не работает –

+0

вы могли бы написать его еще меньше: http://regexr.com/3chi7 '^ ((?: \ +? 1)? 8 [04-8] {2} [2-9] \ д {6}) $ ' – GottZ

Смежные вопросы