Skip to content

Commit 4cb757b

Browse files
committed
Add ValidIranPostalCode rule
1 parent 5e4efee commit 4cb757b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Rules/ValidIranPostalCode.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 ValidIranPostalCode implements Rule
8+
{
9+
/**
10+
* Check postal code is valid.
11+
*
12+
* @param string $attribute
13+
* @param mixed $value
14+
* @return bool
15+
*/
16+
public function passes($attribute, $value)
17+
{
18+
return preg_match('/^(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}$/', $value);
19+
}
20+
21+
/**
22+
* Get the validation error message.
23+
*
24+
* @return string
25+
*/
26+
public function message()
27+
{
28+
return __('validate.postal-code');
29+
}
30+
}

0 commit comments

Comments
 (0)