dart_validators 0.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 49

dart_validators

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

Usage

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';

@Component(
  selector: 'register',
  templateUrl: 'register_component.html',
  directives: const [
    CORE_DIRECTIVES,
    ROUTER_DIRECTIVES,
    formDirectives,
    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... -->
</form>

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.

Changelog

0.0.1

  • Initial version

example/dart_validators_example.dart

import 'package:dart_validators/dart_validators.dart';

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

Use this package as a library

1. Depend on it

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


dependencies:
  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 flutter 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

Analysis

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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

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

Platforms

Detected platforms: Flutter, web, other

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

Suggestions

  • 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 analysis and formatting issues.

    Analysis or formatting checks 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)

Dependencies

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-beta
angular_forms ^1.0.0 1.0.0 2.0.0-beta
Transitive dependencies
analyzer 0.30.0+4 0.32.3
angular_compiler 0.3.0+1 0.4.0-alpha+16
args 1.4.3
async 2.0.7
barback 0.15.2+16
build 0.11.2 0.12.7
build_barback 0.4.0+2 0.5.0+4
charcode 1.1.2
cli_util 0.1.3
code_builder 1.0.4 3.1.1
code_transformers 0.5.1+5
collection 1.14.10
convert 2.0.1
crypto 2.0.5
csslib 0.14.4
dart_style 1.0.9+1 1.1.2
front_end 0.1.0-alpha.4.1 0.1.3
func 1.0.0
glob 1.1.6
html 0.13.3+1
intl 0.15.6
isolate 1.1.0 2.0.1
js 0.6.1
kernel 0.3.0-alpha.1.1 0.3.3
logging 0.11.3+1
matcher 0.12.3
meta 1.1.5
package_config 1.0.3
path 1.6.1
plugin 0.2.0+2
pool 1.3.5
quiver 0.25.0 0.29.0+1
quiver_hashcode 1.0.0
source_gen 0.7.5+1 0.8.3
source_maps 0.10.6
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+9
yaml 2.1.14
Dev dependencies
test ^0.12.0