From 20aee0812fdd233c537337ac88214d2c315af7c5 Mon Sep 17 00:00:00 2001 From: Patryk Hegenberg Date: Tue, 20 Dec 2022 21:23:29 +0100 Subject: [PATCH] Part on Validator Class finished and Part 2 finished --- Validator.php | 14 ++++++++++++++ controllers/note-create.php | 8 +++----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 Validator.php diff --git a/Validator.php b/Validator.php new file mode 100644 index 0000000..11f590e --- /dev/null +++ b/Validator.php @@ -0,0 +1,14 @@ += $min && strlen($value) <= $max; + } + public static function email($value) + { + return filter_var($value, FILTER_VALIDATE_EMAIL); + } +} \ No newline at end of file diff --git a/controllers/note-create.php b/controllers/note-create.php index 7691083..1902de7 100644 --- a/controllers/note-create.php +++ b/controllers/note-create.php @@ -1,4 +1,5 @@ 1000)) { - $errors['body'] = 'The body cann not be more than 1000 characters.'; + if (! Validator::string($_POST['body'], 1, 1000)) { + $errors['body'] = 'A body of no more than 1000 characters is required.'; } if (empty($errors)) {