Skip to content

Commit 92353a3

Browse files
committed
add username rule
1 parent 2f49115 commit 92353a3

31 files changed

+312
-172
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
# Laravel Persian Validation
66

7-
Laravel Persian Validation provides validation for Persian alphabet, number and etc.
7+
The Laravel Persian Validation package offers comprehensive validation for the Persian language, including validation for Persian alphabets, numbers, and other Persian-specific elements. This package allows developers to ensure that their Persian language input data meets the necessary validation criteria, enhancing the reliability and accuracy of their applications. With Laravel Persian Validation, developers can easily incorporate Persian language validation into their Laravel projects, providing a more inclusive and user-friendly experience for Persian-speaking users.
8+
9+
10+
811

912
## Requirement
1013

@@ -19,11 +22,19 @@ Via Composer
1922
$ composer require iamfarhad/validation
2023
```
2124

22-
The package will automatically register itself.
25+
This package is designed to automatically register itself without requiring any additional configuration.
26+
2327

2428
### Translations
2529

26-
If you wish to edit the package translations, you can run the following command to publish them into your `resources/lang` (or `/lang` in Laravel 9.x) folder
30+
If you would like to customize the translations for the Laravel Persian Validation package, you can use the following command to publish them into your project's resources/lang directory:
31+
32+
```bash
33+
php artisan vendor:publish --provider="Iamfarhad\Validation\ValidationRulesServiceProvider" --tag="translations"
34+
35+
```
36+
If you are using Laravel 9.x or later, the translations will be published to the /lang directory instead. Once the translations are published, you can modify them as needed to suit your project's requirements.
37+
2738

2839
```bash
2940
php artisan vendor:publish --provider="Iamfarhad\Validation\ValidationRulesServiceProvider"
@@ -54,6 +65,7 @@ You can access to validation rules by passing the rules key according blew follo
5465
| new CardNumber() | Payment card numbers |
5566
| new Address() | Accept Persian, English and ... alphabet, Persian and English numbers and some special characters |
5667
| new PostalCode() | Iran postal code |
68+
| new Username() | Username format |
5769

5870
### Persian Alphabet
5971
Accept Persian language alphabet according to standard Persian, this is the way you can use this validation rule:
@@ -139,14 +151,20 @@ public function rules()
139151
## Team
140152
This component is developed by the following person(s)
141153

142-
| [![Farhad Zand](https://avatars3.githubusercontent.com/u/1936147?v=3&s=130)](https://github.com/iamfarhad)
143-
--- |
144-
| [Farhad Zand](https://github.com/iamfarhad)
154+
| [![Farhad Zand](https://avatars3.githubusercontent.com/u/1936147?v=3&s=130)](https://github.com/iamfarhad) |
155+
|------------------------------------------------------------------------------------------------------------|
156+
| [Farhad Zand](https://github.com/iamfarhad) |
145157

146158
## Support This Project
147159

148-
Please contribute in package completion. This is the best support.
160+
Great! It's always helpful to have more contributors to a package. Here are a few ways you can contribute to the package completion:
161+
162+
* Report Issues: If you find any bugs or issues with the package, you can report them on the package's GitHub repository. Be sure to provide detailed steps to reproduce the issue and any relevant code snippets.
163+
* Submit Pull Requests: If you have a fix for a bug or an improvement to the package, you can submit a pull request on the package's GitHub repository. Be sure to follow the guidelines for contributing and to test your changes thoroughly.
164+
* Improve Documentation: If you find any gaps in the package's documentation, you can contribute by improving the existing documentation or adding new documentation. You can do this by submitting a pull request on the package's GitHub repository.
165+
* Spread the Word: You can help the package by spreading the word about it on social media, developer forums, and other channels. This can help attract more contributors and users to the package.
149166

167+
Remember that contributing to open-source projects like this package is a collaborative effort, and every little bit helps. Thank you for considering contributing!
150168
## License
151169

152170
The Laravel persian validation Module is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
}
3636
},
3737
"require-dev": {
38-
"orchestra/testbench": "^7.0|^8.0",
39-
"phpunit/phpunit": "^9.4"
38+
"laravel/pint": "^1.6",
39+
"orchestra/testbench": "^7.0|^8.0.4",
40+
"phpunit/phpunit": "^9.6.4",
41+
"rector/rector": "^0.15.18"
4042
},
4143
"extra": {
4244
"laravel": {

pint.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "psr12"
3+
}

rector.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\Set\ValueObject\SetList;
9+
10+
return static function (RectorConfig $rectorConfig): void {
11+
$rectorConfig->paths([
12+
__DIR__ . '/resources',
13+
__DIR__ . '/src',
14+
__DIR__ . '/tests',
15+
]);
16+
17+
// register a single rule
18+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
19+
20+
// define sets of rules
21+
$rectorConfig->sets([
22+
LevelSetList::UP_TO_PHP_80,
23+
SetList::CODE_QUALITY,
24+
SetList::DEAD_CODE,
25+
SetList::EARLY_RETURN,
26+
SetList::CODING_STYLE,
27+
SetList::NAMING,
28+
SetList::PRIVATIZATION
29+
]);
30+
};

resources/lang/en/messages.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
22

33
return [
4-
'persianNumber' => 'must be a persian number.',
5-
'persianAlpha' => 'must be a persian alphabet.',
6-
'persian_alphabet_number' => 'must be a persian alphabet or number.',
7-
'mobile' => 'must be a iran mobile number.',
8-
'shebaNumber' => 'must be a sheba number.',
9-
'nationalCode' => 'must be a iran melli code.',
10-
'isNotPersian' => 'could not be contain persian alpahbet or number.',
11-
'phone' => 'must be a iran phone number.',
12-
'phoneArea' => 'must be a iran phone number with area code.',
13-
'cardNumber' => 'must be a valid payment card number.',
14-
'address' => 'must be a correct address.',
15-
'postalCode' => 'must be a iran postal code.',
4+
'persianNumber' => 'must be a persian number.',
5+
'persianAlpha' => 'must be a persian alphabet.',
6+
'persian_alphabet_number' => 'must be a persian alphabet or number.',
7+
'mobile' => 'must be a iran mobile number.',
8+
'shebaNumber' => 'must be a sheba number.',
9+
'nationalCode' => 'must be a iran melli code.',
10+
'isNotPersian' => 'could not be contain persian alpahbet or number.',
11+
'phone' => 'must be a iran phone number.',
12+
'phoneArea' => 'must be a iran phone number with area code.',
13+
'cardNumber' => 'must be a valid payment card number.',
14+
'address' => 'must be a correct address.',
15+
'postalCode' => 'must be a iran postal code.',
16+
'username' => 'invalid format.',
1617
];

resources/lang/fa/messages.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<?php
22

33
return [
4-
'persianNumber' => 'عدد وارد شده باید فارسی باشد.',
5-
'persianAlpha' => 'حروف وارد شده باید فارسی باشد.',
6-
'persian_alphabet_number' => 'حروف و عدد وارد شده باید فارسی باشد.',
7-
'mobile' => 'شماره همراه قابل قبول نیست.',
8-
'shebaNumber' => 'شماره شبا قابل قبول نیست.',
9-
'nationalCode' => 'کد ملی قابل قبول نیست.',
10-
'isNotPersian' => 'حروف غیر لاتین قابل قبول نیست.',
11-
'phone' => 'شماره تلفن قابل قبول نیست.',
12-
'phoneArea' => 'شماره تلفن قابل قبول نیست.',
13-
'cardNumber' => 'شماره کارت قابل قبول نیست.',
14-
'address' => 'آدرس وارد شده قابل قبول نیست.',
15-
'postalCode' => 'کدپستی وارد شده قابل قبول نیست.',
4+
'persianNumber' => 'عدد وارد شده باید فارسی باشد.',
5+
'persianAlpha' => 'حروف وارد شده باید فارسی باشد.',
6+
'persian_alphabet_number' => 'حروف و عدد وارد شده باید فارسی باشد.',
7+
'mobile' => 'شماره همراه قابل قبول نیست.',
8+
'shebaNumber' => 'شماره شبا قابل قبول نیست.',
9+
'nationalCode' => 'کد ملی قابل قبول نیست.',
10+
'isNotPersian' => 'حروف غیر لاتین قابل قبول نیست.',
11+
'phone' => 'شماره تلفن قابل قبول نیست.',
12+
'phoneArea' => 'شماره تلفن قابل قبول نیست.',
13+
'cardNumber' => 'شماره کارت قابل قبول نیست.',
14+
'address' => 'آدرس وارد شده قابل قبول نیست.',
15+
'postalCode' => 'کدپستی وارد شده قابل قبول نیست.',
16+
'username' => 'نام کاربری وارد شده قابل قبول نیست.',
1617
];

src/Rules/Address.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44

55
use Illuminate\Contracts\Validation\Rule;
66

7-
class Address implements Rule
7+
final class Address implements Rule
88
{
9-
/**
10-
* @var string
11-
*/
12-
protected $attribute;
9+
private ?string $attribute = null;
1310

1411
public function passes($attribute, $value): bool
1512
{
1613
$this->attribute = $attribute;
1714

1815
return preg_match(
19-
"/^[\pL\s\d\-\/\,\،\.\\\\\x{200c}\x{064b}\x{064d}\x{064c}\x{064e}\x{064f}\x{0650}\x{0651}\x{6F0}-\x{6F9}]+$/u",
16+
"#^[\pL\s\d\-\/\,\،\.\\\x{200c}\x{064b}\x{064d}\x{064c}\x{064e}\x{064f}\x{0650}\x{0651}\x{6F0}-\x{6F9}]+$#u",
2017
$value
2118
);
2219
}

src/Rules/CardNumber.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@
44

55
use Illuminate\Contracts\Validation\Rule;
66

7-
class CardNumber implements Rule
7+
final class CardNumber implements Rule
88
{
9-
/**
10-
* @var string
11-
*/
12-
protected $attribute;
9+
private ?string $attribute = null;
1310

1411
public function passes($attribute, $value): bool
1512
{
1613
$this->attribute = $attribute;
1714

18-
if (! preg_match('/^\d{16}$/', $value)) {
15+
if (! preg_match('#^\d{16}$#', $value)) {
1916
return false;
2017
}
18+
2119
$sum = 0;
22-
for ($position = 1; $position <= 16; $position++) {
20+
for ($position = 1; $position <= 16; ++$position) {
2321
$temp = $value[$position - 1];
2422
$temp = $position % 2 === 0 ? $temp : $temp * 2;
2523
$temp = $temp > 9 ? $temp - 9 : $temp;
2624
$sum += $temp;
2725
}
2826

29-
return (bool) ($sum % 10 === 0);
27+
return $sum % 10 === 0;
3028
}
3129

3230
public function message(): string

src/Rules/IsNotPersian.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44

55
use Illuminate\Contracts\Validation\Rule;
66

7-
class IsNotPersian implements Rule
7+
final class IsNotPersian implements Rule
88
{
9-
/**
10-
* @var string
11-
*/
12-
protected $attribute;
9+
private ?string $attribute = null;
1310

1411
public function passes($attribute, $value): bool
1512
{
1613
$this->attribute = $attribute;
1714

1815
if (is_string($value)) {
19-
return ! preg_match("/[\x{600}-\x{6FF}]/u", $value);
16+
return ! preg_match("#[\x{600}-\x{6FF}]#u", $value);
2017
}
2118

2219
return false;

src/Rules/Mobile.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44

55
use Illuminate\Contracts\Validation\Rule;
66

7-
class Mobile implements Rule
7+
final class Mobile implements Rule
88
{
9-
/**
10-
* @var string
11-
*/
12-
protected $attribute;
9+
private ?string $attribute = null;
1310

1411
public function passes($attribute, $value): bool
1512
{
1613
$this->attribute = $attribute;
1714

18-
return preg_match('/^((0)(9){1}[0-9]{9})+$/', $value);
15+
return preg_match('#^((0)(9){1}\d{9})+$#', $value);
1916
}
2017

2118
public function message(): string

0 commit comments

Comments
 (0)