Skip to content

Commit 2debde0

Browse files
committed
v2 commit
1 parent 4817dfa commit 2debde0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+5069
-1259
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
.idea/
2+
.vscode/
13
vendor/
24
composer.lock
35
phpunit.phar
4-
.phpunit.result.cache
6+
.phpunit.result.cache

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) Sadegh Barzegar
3+
Copyright (c) [Sadegh Barzegar](https://github.com/sadegh19b)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+230
Large diffs are not rendered by default.

UPGRADE.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Upgrade Guide
2+
3+
## Upgrading To 2.0 From 1.x
4+
5+
### Minimum PHP Version
6+
The new minimum PHP version is now 8.2.
7+
8+
### Minimum Laravel Version
9+
Laravel Persian Validation 2.0 requires Laravel 11.0 or greater.
10+
11+
### Core Changes
12+
The package now supports two ways to use validation rules:
13+
14+
1. **Using Rule Objects (New Recommended Way)**
15+
```php
16+
use Sadegh19b\LaravelPersianValidation\Rules\PersianAlpha;
17+
use Sadegh19b\LaravelPersianValidation\Rules\IranianMobile;
18+
19+
$request->validate([
20+
'name' => [new PersianAlpha],
21+
'mobile' => [new IranianMobile],
22+
]);
23+
```
24+
25+
2. **Using String Rules (Legacy Way)**
26+
```php
27+
$request->validate([
28+
'name' => 'persian_alpha',
29+
'mobile' => 'ir_mobile',
30+
]);
31+
```
32+
33+
The Rule Objects approach provides better IDE support, type-hinting, and allows for more complex rule configurations.
34+
35+
### Rule Changes
36+
37+
The validation rules have been significantly enhanced in version 2.0:
38+
39+
- All rules now provide more descriptive and user-friendly error messages
40+
- Validation logic has been improved for better accuracy and consistency
41+
- Rule parameters are now more flexible and configurable (see the [readme](README.md) for more details)
42+
- Rules support additional options like Persian number conversion and custom separators
43+
- Each rule has clear documentation of supported formats and examples
44+
- Rules follow consistent patterns for parameter handling and validation
45+
46+
#### New Rules
47+
- `persian_day`: Validates Persian calendar day names
48+
- `persian_month`: Validates Persian calendar month names
49+
- `persian_date_between_year`: Validates dates between specific Persian years
50+
- `persian_date_between_or_equal_year`: Validates dates between or equal to specific Persian years
51+
- `persian_date_between_or_equal`: Validates dates between or equal to specific Persian dates
52+
53+
#### Renamed Rules
54+
- `shamsi_date``persian_date`
55+
- `shamsi_date_between``persian_date_between`
56+
- `ir_national_code``ir_national_id`
57+
- `ir_phone_code``ir_phone_area_code`
58+
- `ir_sheba``ir_iban`
59+
60+
#### Removed Rules
61+
- `ir_phone_with_code` (Use `ir_phone` with options)
62+
- `a_url`
63+
- `a_domain`
64+
65+
### Error Messages
66+
Error messages have been updated to be more descriptive and user-friendly. If you have published the language files, you should review and update them.
67+
68+
### Testing
69+
The testing framework has been updated to PHPUnit 11. You may need to update your test cases if you've extended the package's test classes.

_config.yml

-1
This file was deleted.

composer.json

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
{
22
"name": "sadegh19b/laravel-persian-validation",
3+
"description": "A comprehensive Laravel validation package for Persian text, numbers, dates, and Iranian national identifiers",
4+
"keywords": [
5+
"laravel",
6+
"validation",
7+
"persian",
8+
"farsi",
9+
"validate",
10+
"validator"
11+
],
312
"license": "MIT",
4-
"description": "A persian alphabet, number and etc. validation package for laravel",
5-
"keywords": ["laravel", "validation", "persian", "farsi", "validate", "validator"],
13+
"homepage": "https://github.com/sadegh19b/laravel-persian-validation",
614
"authors": [
715
{
816
"name": "Sadegh Barzegar",
9-
"email": "[email protected]"
17+
"email": "[email protected]",
18+
"homepage": "https://github.com/sadegh19b",
19+
"role": "Developer"
1020
}
1121
],
1222
"require": {
13-
"php": "~7.4|^8.0|^8.1|^8.2",
14-
"illuminate/support": "^6|^7|^8|^9|^10|^11|^12"
23+
"php": ">=8.2",
24+
"illuminate/support": "^11.0|^12.0"
1525
},
16-
"require-dev" : {
17-
"phpunit/phpunit": "^8|^9|^10"
26+
"require-dev": {
27+
"phpunit/phpunit": "^11.0",
28+
"orchestra/testbench": "^9.0"
1829
},
1930
"autoload": {
2031
"psr-4": {
@@ -23,9 +34,13 @@
2334
},
2435
"autoload-dev": {
2536
"psr-4": {
26-
"Tests\\": "tests/"
37+
"Sadegh19b\\LaravelPersianValidation\\Tests\\": "tests/"
2738
}
2839
},
40+
"scripts": {
41+
"test": "vendor/bin/phpunit",
42+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
43+
},
2944
"extra": {
3045
"laravel": {
3146
"providers": [

config/persian-validation.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
return [
3+
/*
4+
* Whether to register the Persian validation rules in Laravel validation container.
5+
* When enabled, you can use the rules directly in validation strings like:
6+
* 'field' => 'required|persian_alpha'
7+
*
8+
* See the README for a complete list of available validation rules.
9+
*/
10+
'register_rules' => true,
11+
12+
/*
13+
* Whether globally to convert Persian/Arabic numbers to English numbers in all persian validation rules that involve numbers.
14+
* When enabled, rules will accept both Persian/Arabic (۰-۹, ٠-٩) and English (0-9) numbers.
15+
* When disabled, only English numbers will be accepted.
16+
*/
17+
'convert_persian_numbers' => false,
18+
];

lang/en/persian-validation.php

+56-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,60 @@
11
<?php
22

33
return [
4-
'persian_alpha' => 'The :attribute must be a persian alphabet.',
5-
'persian_num' => 'The :attribute must be a persian number.',
6-
'persian_alpha_num' => 'The :attribute must be a persian alphabet or number.',
7-
'persian_alpha_eng_num' => 'The :attribute must be a persian alphabet or number or english number.',
8-
'persian_not_accept' => 'The :attribute could not be contain persian alphabet or number.',
9-
'shamsi_date' => 'The :attribute must be a shamsi (jalali) date.',
10-
'shamsi_date_between' => 'The :attribute must be between :afterDate and :beforeDate years of shamsi (jalali) date.',
11-
'ir_mobile' => 'The :attribute must be a iranian mobile number.',
12-
'ir_phone' => 'The :attribute must be a iranian phone number.',
13-
'ir_phone_code' => 'The :attribute must be a iranian phone area code number.',
14-
'ir_phone_with_code' => 'The :attribute must be a iranian phone number with area code.',
15-
'ir_postal_code' => 'The :attribute must be a iranian postal code.',
16-
'ir_bank_card_number' => 'The :attribute must be a valid iranian payment card number.',
17-
'ir_sheba' => 'The :attribute must be a iranian sheba number.',
18-
'ir_national_code' => 'The :attribute must be a iranian national code.',
19-
'a_url' => 'The :attribute is an invalid url.',
20-
'a_domain' => 'The :attribute is an invalid domain.',
21-
'ir_company_id' => 'The :attribute must be a iranian company id.',
4+
'persian_alpha' => 'The :attribute can only contain Persian letters.',
5+
'persian_alpha_num' => 'The :attribute can only contain Persian letters and numbers.',
6+
'persian_alpha_eng_num' => 'The :attribute can only contain Persian letters, numbers, and English numbers.',
7+
'persian_number' => 'The :attribute can only contain Persian numbers.',
8+
'persian_not_accept' => 'The :attribute can\'t contain Persian letters and numbers.',
9+
10+
'persian_date' => 'The :attribute must be a valid persian date. Example: :example',
11+
'persian_date_between' => 'The :attribute must be a persian date between :startDate and :endDate.',
12+
'persian_date_between_or_equal' => 'The :attribute must be a persian date between :startDate and :endDate or equal to them.',
13+
'persian_date_between_year' => 'The :attribute must be between persian years :startYear and :endYear.',
14+
'persian_date_between_or_equal_year' => 'The :attribute must be between persian years :startYear and :endYear or equal to them.',
15+
'persian_day' => 'The :attribute must be one of the persian days of the week (:days).',
16+
'persian_month' => 'The :attribute must be one of the persian months of the year (:months).',
17+
18+
'ir_mobile' => 'The :attribute must be a valid Iranian mobile number. Example: :example',
19+
'ir_mobile_with_country_code' => 'The :attribute must be a valid Iranian mobile number, including the country code. Example: :example',
20+
'ir_phone' => 'The :attribute must be a valid Iranian phone number. Example: :example',
21+
'ir_phone_with_area_code' => 'The :attribute must be a valid Iranian phone number, including the area code. Example: :example',
22+
'ir_phone_with_country_code' => 'The :attribute must be a valid Iranian phone number, including the country code. Example: :example',
23+
'ir_phone_area_code' => 'The :attribute must be one of the Iranian province phone codes. Example: :example',
24+
'ir_postal_code' => 'The :attribute must be a valid Iranian postal code.',
25+
'ir_postal_code_with_separator' => 'The :attribute must be a valid Iranian postal code, including the separator ":separator".',
26+
27+
'ir_bank_card_number' => 'The :attribute must be a valid Iranian bank card number.',
28+
'ir_bank_card_number_with_separator' => 'The :attribute must be a valid Iranian bank card number, including the separator ":separator".',
29+
'ir_iban' => 'The :attribute must be a valid Iranian IBAN number.',
30+
'ir_iban_with_separator' => 'The :attribute must be a valid Iranian IBAN number, including the separator ":separator".',
31+
32+
'ir_national_id' => 'The :attribute must be a valid Iranian national ID.',
33+
'ir_company_id' => 'The :attribute must be a valid Iranian company ID.',
34+
35+
'list_of_persian_week_days' => [
36+
'Shanbe',
37+
'YekShanbe',
38+
'DoShanbe',
39+
'SeShanbe',
40+
'ChaharShanbe',
41+
'PanjShanbe',
42+
'Jome',
43+
],
44+
'list_of_persian_months' => [
45+
'Farvardin',
46+
'Ordibehesht',
47+
'Khordad',
48+
'Tir',
49+
'Mordad',
50+
'Shahrivar',
51+
'Mehr',
52+
'Aban',
53+
'Azar',
54+
'De',
55+
'Bahman',
56+
'Esfand',
57+
],
58+
59+
'space_separator' => 'space',
2260
];

lang/fa/persian-validation.php

+56-21
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,60 @@
11
<?php
22

3-
$invalidMsg = ':attribute معتبر نمی باشد.';
4-
$incorrectMsg = ':attribute صحیح نمی باشد.';
5-
63
return [
7-
'persian_alpha' => ':attribute فقط میتواند شامل حروف فارسی باشد.',
8-
'persian_num' => ':attribute فقط میتواند شامل اعداد فارسی باشد.',
9-
'persian_alpha_num' => ':attribute فقط میتواند شامل حروف و اعداد فارسی باشد.',
10-
'persian_alpha_eng_num' => ':attribute فقط میتواند شامل حروف و اعداد فارسی و اعداد انگلیسی باشد.',
11-
'persian_not_accept' => ':attribute فقط میتواند شامل حروف یا اعداد لاتین باشد.',
12-
'shamsi_date' => $incorrectMsg,
13-
'shamsi_date_between' => ':attribute باید بین سال های :afterDate تا :beforeDate باشد.',
14-
'ir_mobile' => $incorrectMsg,
15-
'ir_phone' => $incorrectMsg,
16-
'ir_phone_code' => $incorrectMsg,
17-
'ir_phone_with_code' => ':attribute باید بهمراه کد استان وارد شود.',
18-
'ir_postal_code' => $invalidMsg,
19-
'ir_bank_card_number' => $invalidMsg,
20-
'ir_sheba' => $invalidMsg,
21-
'ir_national_code' => $invalidMsg,
22-
'a_url' => $incorrectMsg,
23-
'a_domain' => $incorrectMsg,
24-
'ir_company_id' => $invalidMsg,
4+
'persian_alpha' => ':attribute فقط میتواند شامل حروف فارسی باشد.',
5+
'persian_alpha_num' => ':attribute فقط میتواند شامل حروف و اعداد فارسی باشد.',
6+
'persian_alpha_eng_num' => ':attribute فقط میتواند شامل حروف و اعداد فارسی و اعداد انگلیسی باشد.',
7+
'persian_num' => ':attribute فقط میتواند شامل اعداد فارسی باشد.',
8+
'persian_not_accept' => ':attribute فقط میتواند شامل حروف یا اعداد لاتین باشد.',
9+
10+
'persian_date' => ':attribute باید یک تاریخ شمسی معتبر باشد. مثال: :example',
11+
'persian_date_between' => ':attribute باید تاریخی بین :startDate و :endDate باشد.',
12+
'persian_date_between_or_equal' => ':attribute باید تاریخی بین :startDate و :endDate یا برابر با آن باشد.',
13+
'persian_date_between_year' => ':attribute باید بین سال های :startYear تا :endYear باشد.',
14+
'persian_date_between_or_equal_year' => ':attribute باید بین سال های :startYear تا :endYear یا برابر با آن باشد.',
15+
'persian_day' => ':attribute باید یکی از روزهای هفته (:days) باشد.',
16+
'persian_month' => ':attribute باید یکی از ماه های سال (:months) باشد.',
17+
18+
'ir_mobile' => ':attribute باید یک شماره موبایل معتبر باشد. مثال: :example',
19+
'ir_mobile_with_country_code' => ':attribute باید یک شماره موبایل معتبر، بهمراه کد کشور ایران وارد شود. مثال: :example',
20+
'ir_phone' => ':attribute باید یک شماره تلفن معتبر باشد. مثال: :example',
21+
'ir_phone_with_area_code' => ':attribute باید یک شماره تلفن معتبر، بهمراه کد استان وارد شود. مثال: :example',
22+
'ir_phone_with_country_code' => ':attribute باید یک شماره تلفن معتبر، بهمراه کد کشور ایران وارد شود. مثال: :example',
23+
'ir_phone_area_code' => ':attribute باید یکی از کدهای استان های ایران باشد. مثال: :example',
24+
'ir_postal_code' => ':attribute باید یک کد پستی معتبر باشد.',
25+
'ir_postal_code_with_separator' => ':attribute باید یک کد پستی معتبر به همراه جداکننده ":separator" باشد.',
26+
27+
'ir_bank_card_number' => ':attribute باید یک شماره کارت بانکی معتبر باشد.',
28+
'ir_bank_card_number_with_separator' => ':attribute باید یک شماره کارت بانکی معتبر به همراه جداکننده ":separator" باشد.',
29+
'ir_iban' => ':attribute باید یک شماره شبا معتبر باشد.',
30+
'ir_iban_with_separator' => ':attribute باید یک شماره شبا معتبر به همراه جداکننده ":separator" باشد.',
31+
32+
'ir_national_id' => ':attribute باید یک کدملی معتبر باشد.',
33+
'ir_company_id' => ':attribute باید یک شناسه ملی حقوقی معتبر باشد.',
34+
35+
'list_of_persian_week_days' => [
36+
'شنبه',
37+
'یکشنبه',
38+
'دوشنبه',
39+
'سه‌شنبه',
40+
'چهارشنبه',
41+
'پنج‌شنبه',
42+
'جمعه',
43+
],
44+
'list_of_persian_months' => [
45+
'فروردین',
46+
'اردیبهشت',
47+
'خرداد',
48+
'تیر',
49+
'مرداد',
50+
'شهریور',
51+
'مهر',
52+
'آبان',
53+
'آذر',
54+
'دی',
55+
'بهمن',
56+
'اسفند',
57+
],
58+
59+
'space_separator' => 'فاصله',
2560
];

0 commit comments

Comments
 (0)