Skip to main content

bd_phone_validator 1.1.0 copy "bd_phone_validator: ^1.1.0" to clipboard
bd_phone_validator: ^1.1.0 copied to clipboard

Validate, normalize, format and detect the operator (Grameenphone, Robi, Banglalink, Teletalk, Airtel) of Bangladeshi mobile numbers. Pure Dart, zero dependencies.

example/example.dart

// ignore_for_file: avoid_print
import 'package:bd_phone_validator/bd_phone_validator.dart';

void main() {
  // Backward-compatible strict validation.
  print(BdPhoneValidator.validate('+8801712345678')); // true
  print(BdPhoneValidator.validate('0123456789')); // false

  // Lenient validation: separators and Bangla digits.
  print(BdPhoneValidator.validate('+880 1712-345678', strict: false)); // true
  print(BdPhoneValidator.validate('০১৭১২৩৪৫৬৭৮', strict: false)); // true

  // Normalize / E.164.
  print(BdPhoneValidator.normalize('+8801712345678')); // 01712345678
  print(BdPhoneValidator.toE164('01712345678')); // +8801712345678

  // Operator detection.
  print(BdPhoneValidator.detectOperator('01812345678')); // BdOperator.robi

  // Rich parsing.
  final phone = BdPhoneValidator.tryParse('+880 1712-345678');
  if (phone != null) {
    print(phone.operator.displayName); // Grameenphone
    print(phone.formatted); // 01712-345678
    print(phone.masked); // 017XX-XXX678
  }

  // Use with a Flutter TextFormField: validator: BdPhoneValidator.formValidator()
  final validator = BdPhoneValidator.formValidator();
  print(validator('123')); // Enter a valid Bangladeshi phone number
}
3
likes
160
points
134
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Validate, normalize, format and detect the operator (Grameenphone, Robi, Banglalink, Teletalk, Airtel) of Bangladeshi mobile numbers. Pure Dart, zero dependencies.

Repository (GitHub)
View/report issues
Contributing

Topics

#bangladesh #phone #validator #validation

License

MIT (license)

More

Packages that depend on bd_phone_validator