Skip to content

Instantly share code, notes, and snippets.

@shenjiayu
Last active February 27, 2019 21:32
Show Gist options
  • Save shenjiayu/3f63991548ede5f8c34a0a89f89ab74f to your computer and use it in GitHub Desktop.
Save shenjiayu/3f63991548ede5f8c34a0a89f89ab74f to your computer and use it in GitHub Desktop.
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