From 53c9de3d5ecb53344721b86444be8b2f2d3d6d16 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sat, 18 Nov 2017 13:24:25 -0500 Subject: [PATCH] minLength+maxLength matchers --- lib/src/matchers.dart | 10 ++++++++++ pubspec.yaml | 2 +- validate.iml | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 validate.iml diff --git a/lib/src/matchers.dart b/lib/src/matchers.dart index de2d22b8..050b85c3 100644 --- a/lib/src/matchers.dart +++ b/lib/src/matchers.dart @@ -49,3 +49,13 @@ final Matcher isUrl = predicate( /// Use [isUrl] instead. @deprecated final Matcher isurl = isUrl; + +/// Enforces a minimum length on a string. +Matcher minLength(int length) => predicate( + (value) => value is String && value.length >= length, + 'a string at least $length character(s) long'); + +/// Limits the maximum length of a string. +Matcher maxLength(int length) => predicate( + (value) => value is String && value.length >= length, + 'a string no longer than $length character(s) long'); diff --git a/pubspec.yaml b/pubspec.yaml index 8ee46b08..cebf2eea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_validate description: Cross-platform validation library based on `matcher`. -version: 1.0.2+4 +version: 1.0.3 author: Tobe O homepage: https://github.com/angel-dart/validate environment: diff --git a/validate.iml b/validate.iml new file mode 100644 index 00000000..5a5ced28 --- /dev/null +++ b/validate.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file