https://github.com/pro100andrey/validator
Simple validator package
https://github.com/pro100andrey/validator
dart form-validation regex validation validator
Last synced: about 2 months ago
JSON representation
Simple validator package
- Host: GitHub
- URL: https://github.com/pro100andrey/validator
- Owner: pro100andrey
- License: mit
- Created: 2022-04-05T23:40:54.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-16T12:10:12.000Z (5 months ago)
- Last Synced: 2025-03-26T07:42:23.728Z (2 months ago)
- Topics: dart, form-validation, regex, validation, validator
- Language: Dart
- Homepage: https://pub.dev/packages/pro_validator
- Size: 339 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# pro_validator
The validator package comes with several common validations and removes the boiler plate code from your project.
## Features
- Contains several common validations
- Supports grouping of validators to write concise code
- Zero dependency
- Well tested
- Easy to use and removes boiler plate code from your project# How to use
## Install```bash
flutter pub add pro_validator
```## Example
> **_NOTE:_** if validate value contains is a null value, the result is null, not an error.
``` dart
import 'package:pro_validator/pro_validator.dart';void main() {
const emailValidator = MultiValidator(
validators: [
RequiredValidator(error: 'Required field'),
EmailValidator(error: 'Invalid email'),
],
);print('null email validation ${emailValidator(null)}');
print('empty email validation ${emailValidator('')}');
print('invalid email validation ${emailValidator('mail@com')}');
print('valid email validation ${emailValidator('[email protected]')}');const passwordValidator = MultiValidator(
validators: [
RequiredValidator(error: 'Required field'),
MinLengthValidator(min: 8, error: 'Min length 8'),
HasUppercaseValidator(error: 'Must contain at least one uppercase'),
HasLowercaseValidator(error: 'Must contain at least one lowercase'),
],
);print('null password validation ${passwordValidator(null)}');
print('empty password validation ${passwordValidator('')}');
print('min length password validation ${passwordValidator('1232')}');
print('invalid password validation ${passwordValidator('12345678')}');
print('invalid password validation ${passwordValidator('12345678A')}');
print('valid password validation ${passwordValidator('a12345678A')}');final matchValidator = MatchValidator(error: 'Do not match');
print('match validation ${matchValidator('a', 'b')}');
}```
## Available Validators
| Validator | Description |
| - | - |
| RequiredValidator | Ensures the value is not empty, not white space only. |
| MaxLengthValidator | Ensures the value length contains no more than a set [max] of characters. |
| MinLengthValidator | Ensures the value length contains no fewer than a set [min] of characters. |
| HasUppercaseValidator | Ensures the value contains a minimum of one uppercase character. |
| HasLowercaseValidator | Ensures the value contains a minimum of one lowercase character. |
| HasANumberValidator | Ensures the value contains a minimum of one numeric character. |
| LengthRangeValidator | Ensures the value length is contained in the range [min, max]. |
| NumRangeValidator | Ensures the num value is contained in the range [min, max]. |
| EmailValidator | Ensures the value is a validly formatted email address. |
| PhoneValidator | Ensures the value is a validly formatted phone number. |
| UrlValidator | Ensures the value is a validly formatted URL. |
| PatternValidator | Ensures a custom regular expression string. |
| MatchValidator | A special match validator to check if the v1 equals v2 value. |
| MultiValidator | Group together and validate the basic validators. |