jaguar_validate 1.0.0 copy "jaguar_validate: ^1.0.0" to clipboard
jaguar_validate: ^1.0.0 copied to clipboard

outdatedDart 1 only

A super simple fluent Validator framework for Dart

jaguar_validate #

A super simple fluent Validator framework for Dart

Usage #

A simple usage example:

library jaguar_validate.example.simple;

import 'package:jaguar_validate/jaguar_validate.dart';

class Author {
  String name;

  String email;

  @IsInRange(20, 30)
  int age;

  Author.make(this.name, this.email, this.age);

  ObjectErrors validate() {
    ObjectErrors errors = new ObjectErrors();
    Validate.string
        .isNotNull()
        .isNotEmpty(trim: true)
        .startsWithAlpha()
        .hasLengthLessThan(10)
        .setErrors(name, 'name', errors);
    Validate.string
        .isNotNull()
        .isNotEmpty(trim: true)
        .isEmail()
        .setErrors(email, 'email', errors);
    Validate.int
        .isNotNull()
        .isInRange(20, 30)
        .setErrors(age, 'age', errors);
    return errors;
  }
}

main() {
  Author author = new Author.make('Mark', 'mark@books.com', 28);

  ObjectErrors e = author.validate();
  print(e.toJson());
  print(e.hasErrors);
  //=> {}
  //=> false

  author.age = 35;
  e = author.validate();
  print(e.toJson());
  print(e.hasErrors);
  //=> {age: [should be in range [20, 30]!]}
  //=> true

  author.name = '5Mark';
  e = author.validate();
  print(e.toJson());
  print(e.hasErrors);
  //=> {name: [should start with an alphabet!], age: [should be in range [20, 30]!]}
  //=> true

  author.email = 'tejainece@';
  e = author.validate();
  print(e.toJson());
  print(e.hasErrors);
  //=> {name: [should start with an alphabet!], email: [is not an email!], age: [should be in range [20, 30]!]}
  //=> true
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A super simple fluent Validator framework for Dart

Homepage

License

unknown (LICENSE)

More

Packages that depend on jaguar_validate