-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelperFormValidation.php
More file actions
45 lines (33 loc) · 914 Bytes
/
HelperFormValidation.php
File metadata and controls
45 lines (33 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
class HelperFormValidation
{
public array $errors = [];
public function required($data,string $filedName)
{
if(empty($data)) {
$this->errors[] ="This fields $filedName is required";
}
return $this;
}
public function url(string $url)
{
if(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) {
$this->errors[] ="Invalid URL";
}
return $this;
}
public function date(string $date)
{
if(!strtotime($date)) {
$this->errors[] ="Invalid date";
}
return $this;
}
public function dateAfter(string $from, string $to)
{
if(date_create($from) > date_create($to)) {
$this->errors[] ="Invalid date between ! that should $to grater thant $from";
}
return $this;
}
}