From 5f62c57f376fe5b7f2d48afe1b02a4eb6b22d4ed Mon Sep 17 00:00:00 2001 From: Mike Zamayias <29067825+mzamayias@users.noreply.github.com> Date: Sun, 23 Jan 2022 21:09:30 +0200 Subject: [PATCH] validators for contact page --- lib/widgets/text_input/validators.dart | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/widgets/text_input/validators.dart b/lib/widgets/text_input/validators.dart index a320083..0513935 100644 --- a/lib/widgets/text_input/validators.dart +++ b/lib/widgets/text_input/validators.dart @@ -224,4 +224,40 @@ class Validators { } return null; } + + // check name value + String? validateName(String? value) { + if (value == null || value.isEmpty) return 'Name is required'; + if (!RegExp(r'^[a-zA-Z ]+$').hasMatch(value)) { + return 'Name must be alphabetic'; + } + if (value.length < 2) { + return 'Name must be at least 2 characters long'; + } + return null; + } + + // check topic value + String? validateTopic(String? value) { + if (value == null || value.isEmpty) return 'Topic is required'; + if (!RegExp(r'^[a-zA-Z ]+$').hasMatch(value)) { + return 'Topic must be alphabetic'; + } + if (value.length < 2) { + return 'Topic must be at least 2 characters long'; + } + return null; + } + + // check message value + String? validateMessage(String? value) { + if (value == null || value.isEmpty) return 'Message is required'; + if (!RegExp(r'^[a-zA-Z0-9 ]+$').hasMatch(value)) { + return 'Message must be alphanumeric'; + } + if (value.length < 2) { + return 'Message must be at least 2 characters long'; + } + return null; + } }