Skip to content

Commit

Permalink
Rules
Browse files Browse the repository at this point in the history
  • Loading branch information
lilianjin committed Apr 13, 2019
1 parent 3e9d441 commit 5fd22e0
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ A component based on People's Republic of China citizen ID card to obtain the us

## Useing

### Useing in Laravel Validation

> Multi-language add `Please enter a valid Id Card` to your json language package.
```php

use Ofcold\IdentityCard\Rules\IdCard;

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'id_card' => [
'required',
new IdCard
]
];
}
```

#### Verify your Chinese ID card
```php

Expand Down
24 changes: 24 additions & 0 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@

## 使用

### 使用在 Laravel 表单验证

> 多语言增加 `Please enter a valid Id Card` 到你的json语言包中
```php

use Ofcold\IdentityCard\Rules\IdCard;

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'id_card' => [
'required',
new IdCard
]
];
}
```

#### 验证你的身份证号码
```php

Expand Down
46 changes: 46 additions & 0 deletions src/Rules/IdCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Ofcold\IdentityCard\Rules;

use Illuminate\Contracts\Validation\Rule;
use Ofcold\IdentityCard\IdentityCard;

/**
* class IdCard
*
* PHP business application development core system
*
* This content is released under the Business System Toll License (MST)
*
* @link https://ofcold.com
*
* @author Bill Li ([email protected]) [Owner]
*
* @copyright Copyright (c) 2017-2019 Bill Li, Ofcold Institute of Technology. All rights reserved.
*/
class IdCard implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
*
* @return bool
*/
public function passes($attribute, $value)
{
return IdentityCard::make($value, app()->getLocale()) !== false;
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return __('Please enter a valid Id Card');
}
}

0 comments on commit 5fd22e0

Please sign in to comment.