Skip to content

[8.x] Add 'multiple_of' validation rule#34788

Merged
taylorotwell merged 1 commit into
laravel:8.xfrom
timacdonald:mutiple_of
Oct 12, 2020
Merged

[8.x] Add 'multiple_of' validation rule#34788
taylorotwell merged 1 commit into
laravel:8.xfrom
timacdonald:mutiple_of

Conversation

@timacdonald
Copy link
Copy Markdown
Member

@timacdonald timacdonald commented Oct 11, 2020

This validation rule allows devs to validate that a given number is a "multiple of" another number. The naming for this rule comes from the corresponding JSON schema validation rule.

This validation rule can be useful if you use a number input with a step attribute.

Input...

<input type="number" step="0.5" name="foo">

Validation...

public function rules(): array
{
    return [
        'foo' => [
            'multiple_of:0.5',
        ]
    ];
}

Expected result

0 ✅
0.5 ✅
1 ✅
1.5 ✅
1.6 ❌

Would love you to just scan over the data provider and make sure it validates as you would expect.

If ya keen to merge this one I can PR the laravel/laravel repo with a translation, and the laravel/docs repo with some documentation, unless someone jumps in to does it first (anyone reading thing, feel free 👍)

@taylorotwell taylorotwell merged commit b00445e into laravel:8.x Oct 12, 2020
@ejunker
Copy link
Copy Markdown
Contributor

ejunker commented Oct 13, 2020

@timacdonald should add multiple_of to the validation docs

@tontonsb
Copy link
Copy Markdown
Contributor

Why is false considered to be the correct answer for the test cases involving 10.5 and .3? 10.5 is a multiple of .3. Do you know of any browser that supports these attributes but does not allow entering 10.5 in this input?

<input type=number min=0 step=.3 >

@timacdonald
Copy link
Copy Markdown
Member Author

See: #34960 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants