Skip to content

Commit 19af9d4

Browse files
committed
✨ added date validator
1 parent 4987f86 commit 19af9d4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Form.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class Form
3333
'email' => '{field} must be a valid email',
3434
'nospaces' => '{field} can\'t contain any spaces',
3535
'max' => '{field} $field can\'t be more than {params} characters',
36-
'min' => '{field} $field can\'t be less than {params} characters'
36+
'min' => '{field} $field can\'t be less than {params} characters',
37+
'date' => '{field} must be a valid date',
3738
];
3839

3940
/**
@@ -50,6 +51,7 @@ class Form
5051
'nospaces' => null,
5152
'max' => null,
5253
'min' => null,
54+
'date' => null,
5355
];
5456

5557
public static function addError(string $field, string $error)
@@ -170,6 +172,13 @@ protected static function rules()
170172
static::parseMessage('min', $field, $value, $params);
171173
return false;
172174
}
175+
},
176+
'date' => function ($field, $value) {
177+
if (!strtotime($value)) {
178+
static::$errorsArray[$field] =
179+
static::parseMessage('date', $field, $value);
180+
return false;
181+
}
173182
}
174183
];
175184

0 commit comments

Comments
 (0)