Skip to Main Content
Wyra?enia regularne. Receptury
book

Wyra?enia regularne. Receptury

by Jan Goyvaerts, Steven Levithan
May 2010
Intermediate to advanced content levelIntermediate to advanced
520 pages
17h 44m
Polish
Helion
Content preview from Wyra?enia regularne. Receptury

4.3. Weryfikacja międzynarodowych numerów telefonów

Problem

Chcemy sprawdzać poprawność międzynarodowych numerów telefonów. Numery powinny rozpoczynać się od znaku plusa, po którym ma następować kod państwa i numer planu numeracyjnego tego państwa.

Rozwiązanie

Wyrażenie regularne

  • ^\+(?:[0-9]•?){6,14}[0-9]$

    • Opcje wyrażenia regularnego: Brak

    • Odmiany wyrażeń regularnych: .NET, Java, JavaScript, PCRE, Perl, Python, Ruby

JavaScript

function validate (phone) {
    var regex = /^\+(?:[0-9] ?){6,14}[0-9]$/;

    if (regex.test(phone)) {
        // Prawidłowy międzynarodowy numer telefonu.
    } else {
        // Nieprawidłowy międzynarodowy numer telefonu.
    }
}

Pozostałe języki programowania

Lektura „3.5. Sprawdzanie możliwości odnalezienia dopasowania w przetwarzanym łańcuchu” powinna Ci pomóc ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mikrousługi oparte na zdarzeniach

Mikrousługi oparte na zdarzeniach

Adam Bellemare

Publisher Resources

ISBN: 9781457167003