Skip to content

Commit b4494b3

Browse files
committed
add valid base64 rule
1 parent 29a99cb commit b4494b3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Rules/ValidBase64.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Milwad\LaravelValidate\Rules;
4+
5+
use Illuminate\Contracts\Validation\Rule;
6+
7+
class ValidBase64 implements Rule
8+
{
9+
/**
10+
* Check base64.
11+
*
12+
* @param string $attribute
13+
* @param mixed $value
14+
* @return bool
15+
*/
16+
public function passes($attribute, $value)
17+
{
18+
return preg_match('/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/', $value);
19+
}
20+
21+
/**
22+
* Get the validation error message.
23+
*
24+
* @return string
25+
*/
26+
public function message()
27+
{
28+
return __('valid.base64');
29+
}
30+
}

0 commit comments

Comments
 (0)