lanka-validations - v2.1.0
    Preparing search index...

    Function parsePhone

    • Parses and inspects a Sri Lankan phone number (mobile, landline, or short code). Returns PhoneInfo if valid, or null if invalid.

      Parameters

      • rawPhone: unknown

        Phone number in any common format. Strings and finite numbers are accepted; other types return a failure without throwing.

      Returns PhoneInfo | null

      Number type, formats, prefix, area, and originally allocated operator, or null if invalid.

      parsePhone('0771234567')?.type; // 'mobile'
      parsePhone('0771234567')?.international; // '+94 77 123 4567'
      parsePhone('0112345678')?.areaName; // 'Colombo'