dart_validators 0.0.1

  • README.md
  • Example
  • Installing
  • Versions
  • new49


A useful set of validators for using in an AngularDart web application.


Having a component named RegisterComponent, you can use these validators as simple as these snippets:

Code-behind file:

// register_component.dart

import 'package:angular/angular.dart';
import 'package:angular_forms/angular_forms.dart';
import 'package:dart_validators/dart_validators.dart';

  selector: 'register',
  templateUrl: 'register_component.html',
  directives: const [
    VALIDATORS_DIRECTIVES, // dont forgot to import validators directives
class RegisterComponent {
    // all code-behind codes go here...

HTML file:

<!-- register_component.html -->
<form #loginForm="ngForm">
    <!-- all HTML snippets go here... -->

Using EmailValidator

Using EmailValidator basically doesn't need any code-behind and all can be done in HTML bu just adding an email attribute to an input tag -except custom error messages which we will discuss later in this document:

<input type="email" required email />

This will evaluate the input as an email address. But it will not check being required. To do that, you still need use the required attribute.

Using PasswordStrengthValidator

The PasswordStrengthValidator checks if a password input is strength enough or not. To use PasswordStrengthValidator you just need to add a password attribute to element:

<input type="password" required password minlength="8" />

Still, it wouldn't check for being required and you have to add required to check that. Also, since there was a built-in minlength validator, The PasswordStrengthValidator wouldn't check for this too and you have to use the built-in validator.

To get PasswordStrengthValidator to work, you need to set at least one of these configurable attributes to a non-zero value:

  • password-uppercase-count: the minimum count of uppercase letters needed to pass the check
  • password-lowercase-count: the minimum count of lowercase letters needed to pass the check
  • password-numeral-count: the minimum count of numeric characters needed to pass the check
  • password-nonword-count: the minimum count of non-word characters needed to pass the check

Using MatchValidator

The MatchValidator validates an input value against a certain element's value to be exactly same. Usually it's useful to validate a confirm-password's value to be matched with the password's value. To use this validator, you need to 1. identify the source element, 2. put the [should-match] bindable attribute on target element, 3. and pass the source element's identifier to [should-match] attribute on target element:

<!-- identify the source element -->
<input type="password" name="password" #passwordField />

<!-- put attribute and pass identifier to target element -->
<input type="password" name="confirm_password" [should-match]="passwordField" />

Using MethodValidator

Sometimes you need to validate an input value in code-behind. For example checking a username or email availability which needs to call and get result from an API. To do that, you can create a dart method and bind your element's validation flow to it:

// register_component.dart
Map<String, dynamic> validateUsername(AbstractControl c) {
    var u = c.value.toString();
    // do the validation here. For example call an API
    // or whatever you need to validate value:
    if (u == 'javad_amiry')
        return {'username': 'Userame is taken.'};
    return null;

And in HTML pass the method's name to bindable [validator-method] attribute:

<!-- register_component.html -->
<input type="text" [validator-method]="validateUsername" />

The validator method, returns null if validation check passed, and a Map<String, String> in case there is an error -which you can see in above example.

Features and bugs

Please file feature requests and bugs at the issue tracker.



  • Initial version


import 'package:dart_validators/dart_validators.dart';

main() {
  //var awesome = new Awesome();
  //print('awesome: ${awesome.isAwesome}');

1. Depend on it

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

  dart_validators: "^0.0.1"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:

import 'package:dart_validators/dart_validators.dart';
Version Uploaded Documentation Archive
0.0.1 Mar 14, 2018 Go to the documentation of dart_validators 0.0.1 Download dart_validators 0.0.1 archive


We analyzed this package on Mar 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.32.0
  • pana: 0.10.3


Describes how popular the package is relative to other packages. [more]
0 / 100
Code health derived from static analysis. [more]
97 / 100
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:dart_validators/dart_validators.dart.


  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix issues reported by dartanalyzer or dartfmt.

    dartanalyzer or dartfmt reported 4 hints.

    Run dartfmt to format lib/dart_validators.dart.

    Run dartfmt to format lib/src/email_validator.dart.

    Similar analysis of the following files failed:

    • lib/src/method_validator.dart (hint)
    • lib/src/password_strength_validator.dart (hint)


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
angular ^4.0.0 4.0.0+2 5.0.0-alpha+7
angular_forms ^1.0.0 1.0.0 1.0.1-alpha+7
Transitive dependencies
analyzer 0.30.0+4 0.31.1
angular_compiler 0.3.0+1 0.4.0-alpha+7
args 1.4.1
async 2.0.6
barback 0.15.2+14
build 0.11.2 0.12.0+2
build_barback 0.4.0+2 0.5.0+3
charcode 1.1.1
cli_util 0.1.2+1
code_builder 1.0.4 3.0.3
code_transformers 0.5.1+4
collection 1.14.7
convert 2.0.1
crypto 2.0.2+1
csslib 0.14.1
dart_style 1.0.9+1 1.0.10
front_end 0.1.0-alpha.4.1 0.1.0-alpha.10
func 1.0.0
glob 1.1.5
html 0.13.3
intl 0.15.2
isolate 1.1.0
js 0.6.1
kernel 0.3.0-alpha.1.1 0.3.0-alpha.10
logging 0.11.3+1
matcher 0.12.1+4
meta 1.1.2
package_config 1.0.3
path 1.5.1
plugin 0.2.0+2
pool 1.3.4
quiver 0.25.0 0.28.0
quiver_hashcode 1.0.0
source_gen 0.7.5+1 0.7.6
source_maps 0.10.4
source_span 1.4.0
stack_trace 1.9.2
string_scanner 1.0.2
tuple 1.0.1
typed_data 1.1.5
utf 0.9.0+4
watcher 0.9.7+7
yaml 2.1.13
Dev dependencies
test ^0.12.0