Magento 2.2 – Digits Range Validation in UI-form

form-validationmagento2.2ui-formvalidation

How to add digits range validation rule to the input field inside the UI-form?

Best Answer

In case you needed a digits range validation you should pass a range inside the rule's body as a --separated string, like this:

<field name="day" formElement="input">
    <settings>
        <dataType>text</dataType>
        <label translate="true">Day</label>
        <validation>
            <rule name="validate-number" xsi:type="boolean">true</rule>
            <rule name="validate-digits-range" xsi:type="string">1-31</rule>
        </validation>
    </settings>
</field>

which leads to the error The value is not within the specified range. when value less or greater than specified in the rule's body.