Gem 一覧へ戻る
welitonsousa/zod_validation(新しいタブで開きます)
主要言語: Dart
package zod for dart
- star 数
- 11
- watcher 数
- 1
- fork 数
- 4
- issue 数
- 2
- 最終更新
- 2024/03/25
主要言語: Dart
package zod for dart
TextFormField( validator: Zod().required().min(3).email().build, )
password email isEmails min max equals type<T> required cpf cpnj cpfCnpj isDate optional custom
// 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' // } // } ... }
Zod(localeZod: LocaleEN()).required().build, // or Zod.zodLocaleInstance = LocaleEN() // apply in all system
class MyLocale implements ILocaleZod { // implement the required methods in ILocaleZod } Zod(localeZod: MyLocale()).required().build
Feito com ❤️ by Weliton Sousa