mmphone

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 2 Imported by: 0

README

Myanmar Phone Number Validator for Go

mmphone is a package for validating Myanmar phone numbers in Go, it supports Ooredoo, Atom, MPT, MyTel, and also supports Burmese aphabets.

Installation

Install mmphone with the following command

    go get github.com/devnla/mmphone

Usage/Examples

package main

import (
	"fmt"

	"github.com/devnla/mmphone"
)

func main() {
	phoneChecker := mmphone.NewMyanmarPhone()

	phoneNumbers := []string{
		"09977123456",   // Ooredoo
		"+959781234567", // ATOM
		"959440057616",  // MPT WCDMA
		"0949120059",    // MPT CDMA 450 MHz
		"0937128956",    // MPT CDMA 800 MHz
		"09678123456",   // MyTel
		"၀၉၇၇၅၅၄၁၇၉၄",  // ATOM in Burmese numerals
	}

	for _, phoneNumber := range phoneNumbers {
		fmt.Printf("Phone Number: %s\n", phoneNumber)

		// Sanitize phone number
		sanitizedNumber := phoneChecker.SanitizePhoneNumber(phoneNumber)
		fmt.Printf("Sanitized: %s\n", sanitizedNumber)

		// Validate phone number
		isValid := phoneChecker.IsValidMyanmarPhone(phoneNumber)
		fmt.Printf("Is Valid: %v\n", isValid)

		// Get telecom provider
		provider := phoneChecker.GetTelecomName(phoneNumber)
		fmt.Printf("Provider: %s\n", provider)

		// Get network type
		networkType := phoneChecker.GetPhoneNetworkType(phoneNumber)
		fmt.Printf("Network Type: %s\n\n", networkType)
	}
}

Running Tests

To run tests, run the following command

	go test

Acknowledgements

License

MIT

Documentation

Index

Constants

View Source
const (
	OOREDOO = "Ooredoo"
	ATOM    = "ATOM"
	MPT     = "MPT"
	MYTEL   = "MyTel"
	UNKNOWN = "Unknown"

	GSM_TYPE      = "GSM"
	WCDMA_TYPE    = "WCDMA"
	CDMA_450_TYPE = "CDMA 450 MHz"
	CDMA_800_TYPE = "CDMA 800 MHz"
)

Variables

View Source
var (
	OoredooRegex      = regexp.MustCompile(`^(09|\+?959)9(7|6)\d{7}$`)
	AtomRegex         = regexp.MustCompile(`^(09|\+?959)7(9|8|7)\d{7}$`)
	MptRegex          = regexp.MustCompile(`^(09|\+?959)(5\d{6}|4\d{7,8}|2\d{6,8}|3\d{7,8}|6\d{6}|8\d{6}|7\d{7}|9(0|1|9)\d{5,6})$`)
	MyTelRegex        = regexp.MustCompile(`^(09|\+?959)6([5-9])\d{7}$`)
	MyanmarPhoneRegex = regexp.MustCompile(`^(09|\+?950?9|\+?95950?9)\d{7,9}$`)
)

Functions

This section is empty.

Types

type MyanmarPhone

type MyanmarPhone struct{}

func NewMyanmarPhone

func NewMyanmarPhone() *MyanmarPhone

func (*MyanmarPhone) GetPhoneNetworkType

func (mm *MyanmarPhone) GetPhoneNetworkType(phoneNumber string) string

func (*MyanmarPhone) GetTelecomName

func (mm *MyanmarPhone) GetTelecomName(phoneNumber string) string

func (*MyanmarPhone) IsValidMyanmarPhone

func (mm *MyanmarPhone) IsValidMyanmarPhone(phoneNumber string) bool

func (*MyanmarPhone) SanitizePhoneNumber

func (mm *MyanmarPhone) SanitizePhoneNumber(phoneNumber string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL