yiisoft / validator

Yii validator library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
110 stars 36 forks source link

Can rule Integer allow only 'int'? #655

Closed gotyefrid closed 2 months ago

gotyefrid commented 4 months ago

Now "Integer" validator allows three types of variables - they are integer, float and string. Is it possible to make the property accept ONLY integer type?

For example

$rule = new Integer(strict: true);

or

$rule = new Integer(allowTypes: ['int', 'float']);
vjik commented 4 months ago

Currently it is not supported.

I think for this case better make new rule that check value type, and use it combined with Integer rule. For example:

#[Type(allows: [Type::Integer, Type::Float])]
#[Integer(min: 95)]