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
1 change: 1 addition & 0 deletions src/LaravelValidateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class LaravelValidateServiceProvider extends ServiceProvider
*/
protected array $langs = [
'ar',
'az',
'en',
'fa',
'fr',
Expand Down
30 changes: 30 additions & 0 deletions src/Rules/ValidDomain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Milwad\LaravelValidate\Rules;

use Illuminate\Contracts\Validation\Rule;

class ValidDomain implements Rule
{
/**
* Check domain name is valid.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return __('validate.domain');
}
}
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 @@
'car-number' => ':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.',
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 @@
'car-number' => ':attribute غير صالح.',
'cart-number-iran' => ':attribute غير صالح.',
'discord-username' => ':attribute غير صالح.',
'domain' => ':attribute غير صالح.',
'even-number' => ':attribute غير صالح.',
'hashtag' => ':attribute غير صالح.',
'hex-color' => ':attribute غير صالح.',
Expand Down
35 changes: 35 additions & 0 deletions src/lang/az/validate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

return [
'base64' => ':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.',
];
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 @@
'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.',
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 @@
'car-number' => 'مقدار :attribute صحیح نمی باشد.',
'cart-number-iran' => 'مقدار :attribute صحیح نمی باشد.',
'discord-username' => 'مقدار :attribute صحیح نمی باشد.',
'domain' => 'مقدار :attribute صحیح نمی باشد.',
'even-number' => 'مقدار :attribute صحیح نمی باشد.',
'hashtag' => 'مقدار :attribute صحیح نمی باشد.',
'hex-color' => 'مقدار :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 @@
'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.",
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 @@
'car-number' => ':attributeमान्य नहीं है।.',
'cart-number-iran' => ':attributeमान्य नहीं है।.',
'discord-username' => ':attributeमान्य नहीं है।.',
'domain' => ':attributeमान्य नहीं है।.',
'even-number' => ':attributeमान्य नहीं है।.',
'hashtag' => ':attributeमान्य नहीं है।.',
'hex-color' => ':attributeमान्य नहीं है।.',
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 @@
'car-number' => ':attribute有効じゃない。',
'cart-number-iran' => ':attribute有効じゃない。',
'discord-username' => ':attribute有効じゃない。',
'domain' => ':attribute有効じゃない。',
'even-number' => ':attribute有効じゃない。',
'hashtag' => ':attribute有効じゃない。',
'hex-color' => ':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 @@
'car-number' => ':attribute유효하지 않습니다.',
'cart-number-iran' => ':attribute유효하지 않습니다.',
'discord-username' => ':attribute유효하지 않습니다.',
'domain' => ':attribute유효하지 않습니다.',
'even-number' => ':attribute유효하지 않습니다.',
'hashtag' => ':attribute유효하지 않습니다.',
'hex-color' => ':attribute유효하지 않습니다.',
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 @@
'car-number' => ':attribute не действует.',
'cart-number-iran' => ':attribute не действует.',
'discord-username' => ':attribute не действует.',
'domain' => ':attribute не действует.',
'even-number' => ':attribute не действует.',
'hashtag' => ':attribute не действует.',
'hex-color' => ':attribute не действует.',
Expand Down
1 change: 1 addition & 0 deletions src/lang/zh_CN/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'car-number' => ':attribute无效.',
'cart-number-iran' => ':attribute无效.',
'discord-username' => ':attribute无效.',
'domain' => ':attribute无效.',
'even-number' => ':attribute无效.',
'hashtag' => ':attribute无效.',
'hex-color' => ':attribute无效.',
Expand Down
48 changes: 48 additions & 0 deletions tests/ValidDomainTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Milwad\LaravelValidate\Tests;

use Milwad\LaravelValidate\Rules\ValidDomain;

class ValidDomainTest extends BaseTest
{
/**
* Set up.
*/
protected function setUp(): void
{
parent::setUp();
}

/**
* Test domain is valid.
*
* @test
*
* @return void
*/
public function domain_is_valid()
{
$rules = ['domain' => [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);
}
}