Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

补充文档验证器注解@Integer、@Decimal和@Number数据类型的说明 #705

Open
wants to merge 1 commit into
base: 2.1
Choose a base branch
from
Open
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
28 changes: 24 additions & 4 deletions doc/components/validation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ class TestValidate

整数验证

> 能通过整数验证的数据类型为 `int | float | string`
>
> 对于 `string` 类型可参考[数字字符串](https://www.php.net/manual/zh/language.types.numeric-strings.php)
>
> 例如,类似 `5` 、 `5.0` 、 `'5'` 均属于整数
>
> 特殊的,类似 `'5.0'` 这种**带小数点的数字字符串**不属于整数

验证必须为整数:

`@Integer`
Expand All @@ -203,6 +211,14 @@ class TestValidate

小数验证

> 能通过小数验证的数据类型为 `float | string`
>
> 对于 `string` 类型可参考[数字字符串](https://www.php.net/manual/zh/language.types.numeric-strings.php)
>
> 例如,类似 `5.1` 、 `'5.1'` 、 `'5.0'` 均属于小数
>
> 特殊的,类似 `5.0` 这种**小数部分为0的 `float` 值**不属于小数
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.0 算小数吧

Copy link
Member Author

@Eno-CN Eno-CN Jul 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.0 算小数吧

我记得应该是5.0的float值转string后直接就丢失小数点了,然后第二个条件不满足。在整数那里恰好也能过,所以它满足上面提到的整数,而不满足小数的条件。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得这算bug了,应该修复下代码

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整数和小数这两个的判断都有涉及这个问题,我觉得如果能严格判断数据类型就更好了,比如再给个严格模式的选项。


验证必须为小数:

`@Decimal`
Expand All @@ -227,21 +243,25 @@ class TestValidate

数值验证,允许是整数或者小数

> 能通过数值验证的数据类型为 `int | float | string`
>
> 对于 `string` 类型可参考[数字字符串](https://www.php.net/manual/zh/language.types.numeric-strings.php)

验证必须为数值:

`@Decimal`
`@Number`

验证必须为>=10.24的数值:

`@Decimal(min=10.24)`
`@Number(min=10.24)`

验证必须为<=10.24的数值:

`@Decimal(max=10.24)`
`@Number(max=10.24)`

验证必须为>=1 && <=10.24的数值:

`@Decimal(min=1, max=10.24)`
`@Number(min=1, max=10.24)`

> 传入`1`,结果为`true`
>
Expand Down
Loading