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

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

Merged
merged 1 commit into from
Oct 12, 2020
Merged

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

merged 1 commit into from
Oct 12, 2020

Conversation

timacdonald
Copy link
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
Contributor

ejunker commented Oct 13, 2020

@timacdonald should add multiple_of to the validation docs

@tontonsb
Copy link
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
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