Giter Site home page Giter Site logo

siddastic / master_validator Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 321 KB

A simple and quick form validation library for Flutter.

Home Page: https://pub.dev/packages/master_validator

License: MIT License

Kotlin 2.60% Swift 4.33% Objective-C 0.04% Dart 25.54% CMake 27.55% C++ 33.06% C 3.19% Ruby 1.75% HTML 1.94%

master_validator's Introduction

master_validator

Version GitHub Netlify Status

Simple and quick form validation library for Flutter.

  • Easy to get started with
  • Lightweight
  • Customizable Error Messages
  • Validator Chaining


View New Documentation

Getting Started

Installation

Add master_validator as dependency to your flutter project by running the following command in project-root.

flutter pub add master_validator

Then run flutter pub get to install required dependencies.

Check installation tab for more information

Code

Import master_validator package to your dart widgets by writing:

import 'package:master_validator/master_validator.dart';

This makes the Validators class available in your codespace

Basic Required Field Validation

Use Validators.Required() to make a field required.

TextFormField(
    validator: Validators.Required(
        errorMessage : "This field cannot be left empty",
    )
),

Email Validation

TextFormField(
    validator: Validators.Required(
        next : Validators.Email(),
    ),
),

Inbuild Validation methods :

  • Validators.Required()
  • Validators.Email()
  • Validators.Number()
    • with optional integerOnly allowNegative allowDecimal parameters
  • Validators.LengthBetween()
  • Validators.Minlength()
  • Validators.Maxlength()
  • Validators.Url()
  • Validators.Regex()
  • Validators.Equals()
  • Validators.FileName()
  • Validators.DirectoryName()

Every validator has an errorMessage parameter to customize the error message and a next parameter to chain another validator

Using Multiple Validators (Chaining Validators)

All validators take a next argument in which you can specify another validator (a custom function, or another predefined validator) like :

TextFormField(
    validator: Validators.Required(
        next : Validators.Email(
            next : Validators.Maxlength(50)
        ),
    ),
),

Note: While Chaining, Order MATTERS!

NOTE: By default All Validators except Validators.Required() will not throw an error if the data is empty/null, this means if you defined a validator like :

TextFormField(
    validator: Validators.Email(),
),

It means the field acts as an optional field but if something is entered it must qualify as an email, to change this behaviour, and to make the field required, use Validators.Required() before any other validator, for example -

TextFormField(
    validator: Validators.Required(
        next : Validators.Url(),
    ),
),

For detailed usage, check example/lib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.