Skip to content

neryad/dart_phone_checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telephone Check Version

This Dart package helps you validate if a telephone number is well written according to common formats.

Features

  • Validates phone numbers with optional country codes.
  • Supports various phone number formats including spaces, dashes, and parentheses.
  • Easy to use and integrate into any Dart or Flutter project.

Installation

From pub.dev

Run this command:

flutter pub add telephone_check

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
 telephone_check: ^0.1.3

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it Now in your Dart code, you can use:

import 'package:telephone_check/telephone_check.dart';

From GitHub Alternatively, you can install the package directly from the GitHub repository:

Add this to your package's pubspec.yaml file:

dependencies:
  telephone_check:
    git:
      url: https://github.com/yourusername/telephone_check.git

Then, run dart pub get to install the package.

Usage

Import the package in your Dart code:

import 'package:telephone_check/telephone_check.dart';

void main() {
  String number = "+18095563254";
  if (TelephoneChecker.isValid(number)) {
    print('valid');
  } else {
    print('not valid');
  }

  var validTelephone = TelephoneChecker.isValid(number);
  if (validTelephone) {
    print('valid');
  } else {
    print('not valid');
  }
}

Examples

Here's an example of how you might use the telephone_check package in a Flutter application:

import 'package:flutter/material.dart';
import 'package:telephone_check/telephone_check.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    String number = "1-800-555-5555";
    String resultString = '';
    if (TelephoneChecker.isValid(number)) {
      resultString = 'The number: $number you entered is valid';
    } else {
      resultString = 'The number: $number you entered is invalid';
    }

    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Material App Bar'),
        ),
        body: Center(
          child: Container(
            child: Text(resultString),
          ),
        ),
      ),
    );
  }
}

Supported Formats

You can use various types of telephone numbers and codes such as:

  • +1 215-855-0889 (US)
  • +355 69 903 0544 (AL)
  • +57 333 3717545 (CO)
  • and more.

Looking for the npm Version?

Also available on npm! Check it out:

NPM Badge GitHub Repo

Contributing

Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request on GitHub.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -am 'Add new feature').
  5. Push to the branch (git push origin feature-branch).
  6. Create a new Pull Request.

License

MIT

Acknowledgements

  • Inspired by common phone number validation techniques and patterns.

Tech Stack

Dart

Badges

MIT License Pub Publisher

Changelog

To view the history of changes, refer to CHANGELOG.md.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages