From f5bef3b86ab1397e825c35959fb170b32c988ae8 Mon Sep 17 00:00:00 2001 From: taymaz <75164763+taymazmostafaei@users.noreply.github.com> Date: Sat, 11 Mar 2023 11:53:30 +0330 Subject: [PATCH 1/3] add domain validation also update langs for domain --- src/Rules/ValidDomain.php | 31 ++++++++++++++++++++++++ src/lang/It/validate.php | 1 + src/lang/ar/validate.php | 1 + src/lang/en/validate.php | 1 + src/lang/fa/validate.php | 1 + src/lang/fr/validate.php | 1 + src/lang/hi/validate.php | 1 + src/lang/ja/validate.php | 1 + src/lang/ko/validate.php | 1 + src/lang/ru/validate.php | 1 + src/lang/zh_CN/validate.php | 1 + tests/ValidDomainTest.php | 48 +++++++++++++++++++++++++++++++++++++ 12 files changed, 89 insertions(+) create mode 100644 src/Rules/ValidDomain.php create mode 100644 tests/ValidDomainTest.php diff --git a/src/Rules/ValidDomain.php b/src/Rules/ValidDomain.php new file mode 100644 index 00000000..ea480368 --- /dev/null +++ b/src/Rules/ValidDomain.php @@ -0,0 +1,31 @@ + ':attribute non è valido.', 'cart-number-iran' => ':attribute non è valido.', 'discord-username' => ':attribute non è valido.', + 'domain' => ':attribute non è valido.', 'even-number' => ':attribute non è valido.', 'hashtag' => ':attribute non è valido.', 'hex-color' => ':attribute non è valido.', diff --git a/src/lang/ar/validate.php b/src/lang/ar/validate.php index 0dbed312..44af1a3e 100644 --- a/src/lang/ar/validate.php +++ b/src/lang/ar/validate.php @@ -7,6 +7,7 @@ 'car-number' => ':attribute غير صالح.', 'cart-number-iran' => ':attribute غير صالح.', 'discord-username' => ':attribute غير صالح.', + 'domain' => ':attribute غير صالح.', 'even-number' => ':attribute غير صالح.', 'hashtag' => ':attribute غير صالح.', 'hex-color' => ':attribute غير صالح.', diff --git a/src/lang/en/validate.php b/src/lang/en/validate.php index 1fa0d3fa..5a61500d 100644 --- a/src/lang/en/validate.php +++ b/src/lang/en/validate.php @@ -7,6 +7,7 @@ 'car-number' => 'The :attribute is not valid.', 'cart-number-iran' => 'The :attribute is not valid.', 'discord-username' => 'The :attribute is not valid.', + 'domain' => 'The :attribute is not valid.', 'even-number' => 'The :attribute is not valid.', 'hashtag' => 'The :attribute is not valid.', 'hex-color' => 'The :attribute is not valid.', diff --git a/src/lang/fa/validate.php b/src/lang/fa/validate.php index 533d0f97..34a24bce 100644 --- a/src/lang/fa/validate.php +++ b/src/lang/fa/validate.php @@ -7,6 +7,7 @@ 'car-number' => 'مقدار :attribute صحیح نمی باشد.', 'cart-number-iran' => 'مقدار :attribute صحیح نمی باشد.', 'discord-username' => 'مقدار :attribute صحیح نمی باشد.', + 'domain' => 'مقدار :attribute صحیح نمی باشد.', 'even-number' => 'مقدار :attribute صحیح نمی باشد.', 'hashtag' => 'مقدار :attribute صحیح نمی باشد.', 'hex-color' => 'مقدار :attribute صحیح نمی باشد.', diff --git a/src/lang/fr/validate.php b/src/lang/fr/validate.php index 778969ea..2212916a 100644 --- a/src/lang/fr/validate.php +++ b/src/lang/fr/validate.php @@ -7,6 +7,7 @@ 'car-number' => ":attribute n'est pas valide.", 'cart-number-iran' => ":attribute n'est pas valide.", 'discord-username' => ":attribute n'est pas valide.", + 'domain' => ":attribute n'est pas valide.", 'even-number' => ":attribute n'est pas valide.", 'hashtag' => ":attribute n'est pas valide.", 'hex-color' => ":attribute n'est pas valide.", diff --git a/src/lang/hi/validate.php b/src/lang/hi/validate.php index 12736715..b181856d 100644 --- a/src/lang/hi/validate.php +++ b/src/lang/hi/validate.php @@ -7,6 +7,7 @@ 'car-number' => ':attributeमान्य नहीं है।.', 'cart-number-iran' => ':attributeमान्य नहीं है।.', 'discord-username' => ':attributeमान्य नहीं है।.', + 'domain' => ':attributeमान्य नहीं है।.', 'even-number' => ':attributeमान्य नहीं है।.', 'hashtag' => ':attributeमान्य नहीं है।.', 'hex-color' => ':attributeमान्य नहीं है।.', diff --git a/src/lang/ja/validate.php b/src/lang/ja/validate.php index ff95c7e2..47b4d8c0 100644 --- a/src/lang/ja/validate.php +++ b/src/lang/ja/validate.php @@ -7,6 +7,7 @@ 'car-number' => ':attribute有効じゃない。', 'cart-number-iran' => ':attribute有効じゃない。', 'discord-username' => ':attribute有効じゃない。', + 'domain' => ':attribute有効じゃない。', 'even-number' => ':attribute有効じゃない。', 'hashtag' => ':attribute有効じゃない。', 'hex-color' => ':attribute有効じゃない。', diff --git a/src/lang/ko/validate.php b/src/lang/ko/validate.php index c7202c93..5b313eb4 100644 --- a/src/lang/ko/validate.php +++ b/src/lang/ko/validate.php @@ -7,6 +7,7 @@ 'car-number' => ':attribute유효하지 않습니다.', 'cart-number-iran' => ':attribute유효하지 않습니다.', 'discord-username' => ':attribute유효하지 않습니다.', + 'domain' => ':attribute유효하지 않습니다.', 'even-number' => ':attribute유효하지 않습니다.', 'hashtag' => ':attribute유효하지 않습니다.', 'hex-color' => ':attribute유효하지 않습니다.', diff --git a/src/lang/ru/validate.php b/src/lang/ru/validate.php index ce7ce6ed..5b84a723 100644 --- a/src/lang/ru/validate.php +++ b/src/lang/ru/validate.php @@ -7,6 +7,7 @@ 'car-number' => ':attribute не действует.', 'cart-number-iran' => ':attribute не действует.', 'discord-username' => ':attribute не действует.', + 'domain' => ':attribute не действует.', 'even-number' => ':attribute не действует.', 'hashtag' => ':attribute не действует.', 'hex-color' => ':attribute не действует.', diff --git a/src/lang/zh_CN/validate.php b/src/lang/zh_CN/validate.php index 1b1809c5..829051a9 100644 --- a/src/lang/zh_CN/validate.php +++ b/src/lang/zh_CN/validate.php @@ -7,6 +7,7 @@ 'car-number' => ':attribute无效.', 'cart-number-iran' => ':attribute无效.', 'discord-username' => ':attribute无效.', + 'domain' => ':attribute无效.', 'even-number' => ':attribute无效.', 'hashtag' => ':attribute无效.', 'hex-color' => ':attribute无效.', diff --git a/tests/ValidDomainTest.php b/tests/ValidDomainTest.php new file mode 100644 index 00000000..cfd5121b --- /dev/null +++ b/tests/ValidDomainTest.php @@ -0,0 +1,48 @@ + [new ValidDomain()]]; + $data = ['domain' => 'github.com']; + $passes = $this->app['validator']->make($data, $rules)->passes(); + + $this->assertTrue($passes); + } + + /** + * Test domain is not valid. + * + * @test + * + * @return void + */ + public function domain_is_not_valid() + { + $rules = ['domain' => [new ValidDomain()]]; + $data = ['domain' => 'github/com']; + $passes = $this->app['validator']->make($data, $rules)->passes(); + + $this->assertFalse($passes); + } +} From 8cfc1900e2ace608f3803ea68256c3bcee682e2a Mon Sep 17 00:00:00 2001 From: taymaz <75164763+taymazmostafaei@users.noreply.github.com> Date: Sat, 11 Mar 2023 12:00:14 +0330 Subject: [PATCH 2/3] Add Azerbaijani lang --- src/LaravelValidateServiceProvider.php | 1 + src/lang/az/validate.php | 35 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/lang/az/validate.php diff --git a/src/LaravelValidateServiceProvider.php b/src/LaravelValidateServiceProvider.php index e891f97b..7bef86a8 100644 --- a/src/LaravelValidateServiceProvider.php +++ b/src/LaravelValidateServiceProvider.php @@ -13,6 +13,7 @@ class LaravelValidateServiceProvider extends ServiceProvider */ protected array $langs = [ 'ar', + 'az', 'en', 'fa', 'fr', diff --git a/src/lang/az/validate.php b/src/lang/az/validate.php new file mode 100644 index 00000000..fe482294 --- /dev/null +++ b/src/lang/az/validate.php @@ -0,0 +1,35 @@ + ':attribute doğru deyil.', + 'bitcoin-address' => ':attribute doğru deyil.', + 'capital-char-with-number' => ':attribute doğru deyil.', + 'car-number' => ':attribute doğru deyil.', + 'cart-number-iran' => ':attribute doğru deyil.', + 'discord-username' => ':attribute doğru deyil.', + 'domain' => ':attribute doğru deyil.', + 'even-number' => ':attribute doğru deyil.', + 'hashtag' => ':attribute doğru deyil.', + 'hex-color' => ':attribute doğru deyil.', + 'html-tag' => ':attribute doğru deyil.', + 'imei' => ':attribute doğru deyil.', + 'ipv4' => ':attribute doğru deyil.', + 'ipv6' => ':attribute doğru deyil.', + 'jwt' => ':attribute doğru deyil.', + 'name-days-week' => ':attribute doğru deyil.', + 'national-card' => ':attribute doğru deyil.', + 'odd-number' => ':attribute doğru deyil.', + 'phone-number' => ':attribute doğru deyil.', + 'port' => ':attribute doğru deyil.', + 'slash-end-of-string' => ':attribute doğru deyil.', + 'slug' => ':attribute doğru deyil.', + 'strong-password' => ':attribute doğru deyil.', + 'url' => ':attribute doğru deyil.', + 'username' => ':attribute doğru deyil.', + 'uuid' => ':attribute doğru deyil.', + 'jalali_date' => ':attribute doğru deyil.', + 'duplicate_character' => ':attribute doğru deyil.', + 'pattern' => ':attribute doğru deyil.', + 'duplicate' => ':attribute doğru deyil.', + 'ulid' => ':attribute doğru deyil.', +]; From 6aa2ec8ffae520ac01a315c66ff54d4d6603fdd8 Mon Sep 17 00:00:00 2001 From: Milwad <98118400+milwad-dev@users.noreply.github.com> Date: Sat, 11 Mar 2023 12:14:38 +0330 Subject: [PATCH 3/3] inline regex for ValidDomain --- src/Rules/ValidDomain.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Rules/ValidDomain.php b/src/Rules/ValidDomain.php index ea480368..ad2db125 100644 --- a/src/Rules/ValidDomain.php +++ b/src/Rules/ValidDomain.php @@ -15,8 +15,7 @@ class ValidDomain implements Rule */ public function passes($attribute, $value) { - $pattern = '/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/'; - return preg_match($pattern, $value); + return preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $value); } /**