Easy form validation

The easy_form_validation package streamlines form validation in Flutter, covering essentials like empty fields, emails, dates of birth, and phone numbers. It also includes Aadhaar card validation, enhancing the ease and accuracy of form validation processes.

Installation

  1. Add the latest version of package to your pubspec.yaml (and rundart pub get):
dependencies:
  easy_form_validator: 0.0.2
  1. Import the package and use it in your Flutter App.
import 'package:easy_form_validator/easy_form_validator.dart';

Example


/// 1 to check Empty or null validation
class EasyScreen extends StatelessWidget {  
  const EasyScreen({Key? key}) : super(key: key);
  final _formKey = GlobalKey<FormState>();
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      body: Form(
        key:_formKey,  
        child: Colum(children:[
          TextFormField(
            validator: (onValue) {
              /// it is use for empty validation
              /// you can also change its default [error] message , default [validation] error message  and isMandatory [by default its true] properties bellow
              /// return onEmail.isNotEmptyNotNull(emptyErrorMsg: "Please Enter Something in text form field",isMandatory: true );
              return onValue.isNotEmptyNotNull(); 
            },
          ),
          // Add more TextFormField widgets for other fields
          ElevatedButton(
            onPressed: () {
              if (_formKey.currentState!.validate()) {
                _formKey.currentState!.save();
                // Form is valid, process the data
                // For example, submit the form or update state
              }
            },
            child: Text('Submit'),
          ),
        ],)
      ),  
    );  
  } 
  
}
/// 2 to check Email validation
class EasyScreen extends StatelessWidget {  
  const EasyScreen({Key? key}) : super(key: key);
  final _formKey = GlobalKey<FormState>();
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      body: Form(
        key:_formKey,  
        child: Colum(children:[
          TextFormField(
            validator: (onEmail) {
              /// it is use for empty validation
              /// you can also change its default [error] message and default [validation] error message like bellow
              /// return onEmail.isValidEmail(emailErrorValidationMsg: "email invalid",emptyErrorMsg: "Please Enter Something in Textformfiled",);
              return onEmail.isValidEmail(); 
            },
          ),
          // Add more TextFormField widgets for other fields
          ElevatedButton(
            onPressed: () {
              if (_formKey.currentState!.validate()) {
                _formKey.currentState!.save();
                // Form is valid, process the data
                // For example, submit the form or update state
              }
            },
            child: Text('Submit'),
          ),
        ],)
      ),  
    );  
  } 
  
}
/// 3 to check Phone number validation
class EasyScreen extends StatelessWidget {  
  const EasyScreen({Key? key}) : super(key: key);
  final _formKey = GlobalKey<FormState>();
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      body: Form(
        key:_formKey,  
        child: Colum(children:[
          TextFormField(
            validator: (onPhoneNumber) {
              /// it is use for empty validation
              /// you can also change its default [error] message and default [validation] error message like bellow
              /// [this one is used to only check phone number count]
              /// return onEmail.isValidPhoneNumberLength(
              ///     phoneNoLength: 10
              /// );
              return onEmail.isValidPhoneNumber(
                  countryCode: Country.IN,
                  isMandatory: true,
                  emptyErrorMsg: "here you can add your empty error messge",
                  phoneNumberErrorValidationMsg: "here you can add validation message",
                  wantSkipCountryCodeNo:true
              );
            },
          ),
          // Add more TextFormField widgets for other fields
          ElevatedButton(
            onPressed: () {
              if (_formKey.currentState!.validate()) {
                _formKey.currentState!.save();
                // Form is valid, process the data
                // For example, submit the form or update state
              }
            },
            child: Text('Submit'),
          ),
        ],)
      ),  
    );  
  } 
  
}
/// 4 to check Password validation
class EasyScreen extends StatelessWidget {  
  const EasyScreen({Key? key}) : super(key: key);
  final _formKey = GlobalKey<FormState>();
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      body: Form(
        key:_formKey,  
        child: Colum(children:[
          TextFormField(
            validator: (onPassword) {
              /// it is use for empty validation
              /// you can also change its default [error] message and default [validation] error message like bellow
              return onPassword.isValidPassword(
                minPass: 2,
                maxPass: 8,
                hasDigit: true,
                hasLowercase: true,
                hasUppercase: true,
                enterSpecialCharacter:"!@_",
                emptyErrorMsg: "Please Enter Something in text form field",
                isMandatory: true
              );
            },
          ),
          // Add more TextFormField widgets for other fields
          ElevatedButton(
            onPressed: () {
              if (_formKey.currentState!.validate()) {
                _formKey.currentState!.save();
                // Form is valid, process the data
                // For example, submit the form or update state
              }
            },
            child: Text('Submit'),
          ),
        ],)
      ),  
    );  
  } 
  
}
/// 5 to check username validation
class EasyScreen extends StatelessWidget {  
  const EasyScreen({Key? key}) : super(key: key);
  final _formKey = GlobalKey<FormState>();
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      body: Form(
        key:_formKey,  
        child: Colum(children:[
          TextFormField(
            validator: (onUsername) {
              /// it is use for empty validation
              /// you can also change its default [error] message and default [validation] error message like bellow
              return onUsername.isValidUsername();
            },
          ),
          // Add more TextFormField widgets for other fields
          ElevatedButton(
            onPressed: () {
              if (_formKey.currentState!.validate()) {
                _formKey.currentState!.save();
                // Form is valid, process the data
                // For example, submit the form or update state
              }
            },
            child: Text('Submit'),
          ),
        ],)
      ),  
    );  
  } 
  
}
/// 6 to check DOB validation
class EasyScreen extends StatelessWidget {  
  const EasyScreen({Key? key}) : super(key: key);
  final _formKey = GlobalKey<FormState>();
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      body: Form(
        key:_formKey,  
        child: Colum(children:[
          TextFormField(
            validator: (onDOB) {
              /// it is use for empty validation
              /// you can also change its default [error] message and default [validation] error message like bellow
              List? lstDate = onDOB?.split("/");
              if ((lstDate?.isNotEmpty ?? false) && (lstDate!.length != 3)) return "invalid date";
              int? day = int.tryParse(lstDate?.first);
              int? month = int.tryParse(lstDate?[1]);
              int? year = int.tryParse(lstDate?.last);
              // DateTime datetime = DateTime(2002, 02, 27); //[either you can check it directly like this]
              if (day == null || month == null || year == null) return "invalid date";
              DateTime datetime = DateTime(year, month, day);
              return datetime.isValidDOB();
            },
          ),
          // Add more TextFormField widgets for other fields
          ElevatedButton(
            onPressed: () {
              if (_formKey.currentState!.validate()) {
                _formKey.currentState!.save();
                // Form is valid, process the data
                // For example, submit the form or update state
              }
            },
            child: Text('Submit'),
          ),
        ],)
      ),  
    );  
  } 
  
}
/// 6 to check Aadhaar card validation
class EasyScreen extends StatelessWidget {  
  const EasyScreen({Key? key}) : super(key: key);
  final _formKey = GlobalKey<FormState>();
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      body: Form(
        key:_formKey,  
        child: Colum(children:[
          TextFormField(
            validator: (onAadhaarCard) {
              /// it is use for empty validation
              /// you can also change its default [error] message and default [validation] error message like bellow
              return onAadhaarCard.isValidAadhaarCardNo();
            },
          ),
          // Add more TextFormField widgets for other fields
          ElevatedButton(
            onPressed: () {
              if (_formKey.currentState!.validate()) {
                _formKey.currentState!.save();
                // Form is valid, process the data
                // For example, submit the form or update state
              }
            },
            child: Text('Submit'),
          ),
        ],)
      ),  
    );  
  } 
  
}
## Next Goals
  • x Add more validation features

  • x Make more easy validation

  • Add more validation functionality.