Last updated:
0 purchases
zod validation
Zod #
Usage with Flutter #
TextFormField(
validator: Zod().required().min(3).email().build,
)
copied to clipboard
All Validations #
password
email
isEmails
min
max
equals
type<T>
required
cpf
cpnj
cpfCnpj
isDate
optional
custom
copied to clipboard
Usage with Shelf #
// register user route
@Route.post('/register')
Future<Response> register (Request req) async {
final data = jsonDecode(await req.readAsString());
final requiredParams = {
'email': Zod().email(),
'password': Zod().password(),
'data': {
'user_name': Zod().min(8).max(20)
'platform': Zod().type<String>(),
},
};
final zod = Zod.validate(data: data, params: requiredParams);
if (zod.isNotValid) {
return Response(400, body: jsonEncode({
'message': 'invalid params',
'params': zod.result
}))
}
// zod.result is a Map that contains the invalid parameters key, and a message
// example:
// {
// 'data': {
// 'user_name': 'At least 8 characters'
// }
// }
...
}
copied to clipboard
How change locale #
Zod(localeZod: LocaleEN()).required().build,
// or
Zod.zodLocaleInstance = LocaleEN() // apply in all system
copied to clipboard
Create your Locale #
class MyLocale implements ILocaleZod {
// implement the required methods in ILocaleZod
}
Zod(localeZod: MyLocale()).required().build
copied to clipboard
Feito com ❤️ by Weliton Sousa
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.