Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 34 additions & 33 deletions README.md

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions config/laravel-validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,167 @@
* If you want to use rules like 'required|ValidPhone' in your validations, you can change it to true.
*/
'using_container' => false,

/*
* The list of country names.
*
* If any country name is missing from this list, you can add your country name to this array.
*/
'countries' => [
'AF' => 'Afghanistan',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AG' => 'Antigua and Barbuda',
'AR' => 'Argentina',
'AM' => 'Armenia',
'AU' => 'Australia',
'AT' => 'Austria',
'AZ' => 'Azerbaijan',
'BS' => 'Bahamas',
'BH' => 'Bahrain',
'BD' => 'Bangladesh',
'BB' => 'Barbados',
'BY' => 'Belarus',
'BE' => 'Belgium',
'BZ' => 'Belize',
'BJ' => 'Benin',
'BT' => 'Bhutan',
'BO' => 'Bolivia',
'BA' => 'Bosnia and Herzegovina',
'BW' => 'Botswana',
'BR' => 'Brazil',
'BN' => 'Brunei',
'BG' => 'Bulgaria',
'BF' => 'Burkina Faso',
'BI' => 'Burundi',
'KH' => 'Cambodia',
'CM' => 'Cameroon',
'CA' => 'Canada',
'CV' => 'Cape Verde',
'CF' => 'Central African Republic',
'TD' => 'Chad',
'CL' => 'Chile',
'CN' => 'China',
'CO' => 'Colombia',
'KM' => 'Comoros',
'CG' => 'Congo',
'CR' => 'Costa Rica',
'HR' => 'Croatia',
'CU' => 'Cuba',
'CY' => 'Cyprus',
'CZ' => 'Czech Republic',
'DK' => 'Denmark',
'DJ' => 'Djibouti',
'DM' => 'Dominica',
'DO' => 'Dominican Republic',
'EC' => 'Ecuador',
'EG' => 'Egypt',
'SV' => 'El Salvador',
'GQ' => 'Equatorial Guinea',
'ER' => 'Eritrea',
'EE' => 'Estonia',
'ET' => 'Ethiopia',
'FJ' => 'Fiji',
'FI' => 'Finland',
'FR' => 'France',
'GA' => 'Gabon',
'GM' => 'Gambia',
'GE' => 'Georgia',
'DE' => 'Germany',
'GH' => 'Ghana',
'GR' => 'Greece',
'GD' => 'Grenada',
'GT' => 'Guatemala',
'GN' => 'Guinea',
'GY' => 'Guyana',
'HT' => 'Haiti',
'HN' => 'Honduras',
'HU' => 'Hungary',
'IS' => 'Iceland',
'IN' => 'India',
'ID' => 'Indonesia',
'IR' => 'Iran',
'IQ' => 'Iraq',
'IE' => 'Ireland',
'IL' => 'Israel',
'IT' => 'Italy',
'JM' => 'Jamaica',
'JP' => 'Japan',
'JO' => 'Jordan',
'KZ' => 'Kazakhstan',
'KE' => 'Kenya',
'KR' => 'South Korea',
'KW' => 'Kuwait',
'KG' => 'Kyrgyzstan',
'LA' => 'Laos',
'LV' => 'Latvia',
'LB' => 'Lebanon',
'LY' => 'Libya',
'LT' => 'Lithuania',
'LU' => 'Luxembourg',
'MG' => 'Madagascar',
'MY' => 'Malaysia',
'MV' => 'Maldives',
'ML' => 'Mali',
'MT' => 'Malta',
'MX' => 'Mexico',
'MD' => 'Moldova',
'MC' => 'Monaco',
'MN' => 'Mongolia',
'ME' => 'Montenegro',
'MA' => 'Morocco',
'MZ' => 'Mozambique',
'MM' => 'Myanmar',
'NA' => 'Namibia',
'NP' => 'Nepal',
'NL' => 'Netherlands',
'NZ' => 'New Zealand',
'NI' => 'Nicaragua',
'NE' => 'Niger',
'NG' => 'Nigeria',
'NO' => 'Norway',
'OM' => 'Oman',
'PK' => 'Pakistan',
'PA' => 'Panama',
'PY' => 'Paraguay',
'PE' => 'Peru',
'PH' => 'Philippines',
'PL' => 'Poland',
'PT' => 'Portugal',
'QA' => 'Qatar',
'RO' => 'Romania',
'RU' => 'Russia',
'SA' => 'Saudi Arabia',
'SN' => 'Senegal',
'RS' => 'Serbia',
'SG' => 'Singapore',
'SK' => 'Slovakia',
'SI' => 'Slovenia',
'ZA' => 'South Africa',
'ES' => 'Spain',
'LK' => 'Sri Lanka',
'SE' => 'Sweden',
'CH' => 'Switzerland',
'SY' => 'Syria',
'TW' => 'Taiwan',
'TJ' => 'Tajikistan',
'TH' => 'Thailand',
'TN' => 'Tunisia',
'TR' => 'Turkey',
'TM' => 'Turkmenistan',
'UA' => 'Ukraine',
'AE' => 'United Arab Emirates',
'GB' => 'United Kingdom',
'US' => 'United States',
'UY' => 'Uruguay',
'UZ' => 'Uzbekistan',
'VE' => 'Venezuela',
'VN' => 'Vietnam',
'YE' => 'Yemen',
'ZM' => 'Zambia',
'ZW' => 'Zimbabwe',
],
];
34 changes: 34 additions & 0 deletions docs/1.x/valid-country.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## ValidCountry

If you want to validate the country name, you can use the `ValidCountry` rule:

```php
use Milwad\LaravelValidate\Rules\ValidCountry;

return [
'country' => ['required', new ValidCountry()], // country => United Arab Emirates
];
```

Also, you can validate country name by key like "AE":

```php
use Milwad\LaravelValidate\Rules\ValidCountry;

return [
'country' => ['required', new ValidCountry(validByKey: true)], // country => "AE"
];
```

For see the list of country name, you can open `config/laravel-validate.php`, and go to `countries` key:

```php
/*
* The list of country names.
*
* If any country name is missing from this list, you can add your country name to this array.
*/
'countries' => [...],
```

> If any country name is missing from this list, you can add your country name to this array.
35 changes: 35 additions & 0 deletions src/Rules/ValidCountry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Milwad\LaravelValidate\Rules;

use Illuminate\Contracts\Validation\Rule;

class ValidCountry implements Rule
{
public function __construct(
protected bool $validByKey = false,
) {}

/**
* Check country name is valid.
*/
public function passes($attribute, $value): bool
{
$countries = config('laravel-validate.countries', []);

// Check value exists in country keys
if ($this->validByKey) {
return array_key_exists($value, $countries);
}

return in_array($value, $countries);
}

/**
* Get the validation error message.
*/
public function message(): string
{
return __('validate.country');
}
}
1 change: 1 addition & 0 deletions src/lang/It/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute non è valido.',
'car-number' => ':attribute non è valido.',
'cart-number-iran' => ':attribute non è valido.',
'country' => ':attribute non è valido.',
'credit-card' => ':attribute non è valido.',
'discord-username' => ':attribute non è valido.',
'domain' => ':attribute non è valido.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/ar/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute غير صالح.',
'car-number' => ':attribute غير صالح.',
'cart-number-iran' => ':attribute غير صالح.',
'country' => ':attribute غير صالح.',
'credit-card' => ':attribute غير صالح.',
'discord-username' => ':attribute غير صالح.',
'domain' => ':attribute غير صالح.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/az/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute doğru deyil.',
'car-number' => ':attribute doğru deyil.',
'cart-number-iran' => ':attribute doğru deyil.',
'country' => ':attribute doğru deyil.',
'credit-card' => ':attribute doğru deyil.',
'discord-username' => ':attribute doğru deyil.',
'domain' => ':attribute doğru deyil.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/bn/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute বৈধ নয়.',
'car-number' => ':attribute বৈধ নয়.',
'cart-number-iran' => ':attribute বৈধ নয়.',
'country' => ':attribute বৈধ নয়.',
'credit-card' => ':attribute বৈধ নয়.',
'discord-username' => ':attribute বৈধ নয়.',
'domain' => ':attribute বৈধ নয়.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/ca/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute no és vàlid.',
'car-number' => ':attribute no és vàlid.',
'cart-number-iran' => ':attribute no és vàlid.',
'country' => ':attribute no és vàlid.',
'credit-card' => ':attribute no és vàlid.',
'discord-username' => ':attribute no és vàlid.',
'domain' => ':attribute no és vàlid.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/de/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute kein gültiger.',
'car-number' => ':attribute kein gültiger.',
'cart-number-iran' => ':attribute kein gültiger.',
'country' => ':attribute kein gültiger.',
'credit-card' => ':attribute kein gültiger.',
'discord-username' => ':attribute kein gültiger.',
'domain' => ':attribute kein gültiger.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/el/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => 'Το :attribute δεν είναι έγκυρο.',
'car-number' => 'Το :attribute δεν είναι έγκυρο.',
'cart-number-iran' => 'Το :attribute δεν είναι έγκυρο.',
'country' => 'Το :attribute δεν είναι έγκυρο.',
'credit-card' => 'Το :attribute δεν είναι έγκυρο.',
'discord-username' => 'Το :attribute δεν είναι έγκυρο.',
'domain' => 'Το :attribute δεν είναι έγκυρο.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/en/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => 'The :attribute is not valid.',
'car-number' => 'The :attribute is not valid.',
'cart-number-iran' => 'The :attribute is not valid.',
'country' => 'The :attribute is not valid.',
'credit-card' => 'The :attribute is not valid.',
'discord-username' => 'The :attribute is not valid.',
'domain' => 'The :attribute is not valid.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/es/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute no es válido.',
'car-number' => ':attribute no es válido.',
'cart-number-iran' => ':attribute no es válido.',
'country' => ':attribute no es válido.',
'credit-card' => ':attribute no es válido.',
'discord-username' => ':attribute no es válido.',
'domain' => ':attribute no es válido.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/fa/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => 'مقدار :attribute صحیح نمی باشد.',
'car-number' => 'مقدار :attribute صحیح نمی باشد.',
'cart-number-iran' => 'مقدار :attribute صحیح نمی باشد.',
'country' => 'مقدار :attribute صحیح نمی باشد.',
'credit-card' => 'مقدار :attribute صحیح نمی باشد.',
'discord-username' => 'مقدار :attribute صحیح نمی باشد.',
'domain' => 'مقدار :attribute صحیح نمی باشد.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/fr/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ":attribute n'est pas valide.",
'car-number' => ":attribute n'est pas valide.",
'cart-number-iran' => ":attribute n'est pas valide.",
'country' => ":attribute n'est pas valide.",
'credit-card' => ":attribute n'est pas valide.",
'discord-username' => ":attribute n'est pas valide.",
'domain' => ":attribute n'est pas valide.",
Expand Down
1 change: 1 addition & 0 deletions src/lang/hi/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attributeमान्य नहीं है।.',
'car-number' => ':attributeमान्य नहीं है।.',
'cart-number-iran' => ':attributeमान्य नहीं है।.',
'country' => ':attributeमान्य नहीं है।.',
'credit-card' => ':attributeमान्य नहीं है।.',
'discord-username' => ':attributeमान्य नहीं है।.',
'domain' => ':attributeमान्य नहीं है।.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/id/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':Attribute tidak valid.',
'car-number' => ':Attribute tidak valid.',
'cart-number-iran' => ':Attribute tidak valid.',
'country' => ':Attribute tidak valid.',
'credit-card' => ':Attribute tidak valid.',
'discord-username' => ':Attribute tidak valid.',
'domain' => ':Attribute tidak valid.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/ja/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute有効じゃない。',
'car-number' => ':attribute有効じゃない。',
'cart-number-iran' => ':attribute有効じゃない。',
'country' => ':attribute有効じゃない。',
'credit-card' => ':attribute有効じゃない。',
'discord-username' => ':attribute有効じゃない。',
'domain' => ':attribute有効じゃない。',
Expand Down
1 change: 1 addition & 0 deletions src/lang/ko/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute유효하지 않습니다.',
'car-number' => ':attribute유효하지 않습니다.',
'cart-number-iran' => ':attribute유효하지 않습니다.',
'country' => ':attribute유효하지 않습니다.',
'credit-card' => ':attribute유효하지 않습니다.',
'discord-username' => ':attribute유효하지 않습니다.',
'domain' => ':attribute유효하지 않습니다.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/ku_so/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'car-number' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'cart-number-iran' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'country' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'credit-card' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'discord-username' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
'domain' => 'ئەو :attribute هەڵبژێردراوە نادروستە.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/mk/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => 'Невалидна вредност :attribute',
'car-number' => 'Невалидна вредност :attribute',
'cart-number-iran' => 'Невалидна вредност :attribute',
'country' => 'Невалидна вредност :attribute',
'credit-card' => 'Невалидна вредност :attribute',
'discord-username' => 'Невалидна вредност :attribute',
'domain' => 'Невалидна вредност :attribute',
Expand Down
1 change: 1 addition & 0 deletions src/lang/pt_BR/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => 'O :attribute não é válido.',
'car-number' => 'O :attribute não é válido.',
'cart-number-iran' => 'O :attribute não é válido.',
'country' => 'O :attribute não é válido.',
'credit-card' => 'O :attribute não é válido.',
'discord-username' => 'O :attribute não é válido.',
'domain' => 'O :attribute não é válido.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/ru/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute не действует.',
'car-number' => ':attribute не действует.',
'cart-number-iran' => ':attribute не действует.',
'country' => ':attribute не действует.',
'credit-card' => ':attribute не действует.',
'discord-username' => ':attribute не действует.',
'domain' => ':attribute не действует.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/si/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'capital-char-with-number' => ':attribute වලංගු නොවේ.',
'car-number' => ':attribute වලංගු නොවේ.',
'cart-number-iran' => ':attribute වලංගු නොවේ.',
'country' => ':attribute වලංගු නොවේ.',
'credit-card' => ':attribute වලංගු නොවේ.',
'discord-username' => ':attribute වලංගු නොවේ.',
'domain' => ':attribute වලංගු නොවේ.',
Expand Down
Loading
Loading