Last active
February 27, 2019 21:32
-
-
Save shenjiayu/3f63991548ede5f8c34a0a89f89ab74f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Validator { | |
static Map<String, Function> _rules = { | |
'required': (String value) { | |
if (value.isEmpty) return false; | |
return true; | |
}, | |
// extends to support more rules, | |
// such as between:1,10 | |
// min:1 | |
// max:10 | |
}; | |
static bool validate(String rule, String value) { | |
// TODO, check if the rule exists | |
return Validator._rules[rule](value); | |
} | |
} | |
void main() { | |
print(Validator.validate('required', '123')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment