7

I want to validate text field to numeric or not in UI form.

<column name="sortorder">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" translate="true" xsi:type="string">SortOrder</item>
            <item name="editor" xsi:type="array">
                <item name="editorType" xsi:type="string">text</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">false</item>
                </item>
            </item>
        </item>
    </argument>
</column>

Can anyone provide list of validation in UI form in

<item name="validation" xsi:type="array">
    <item name="required-entry" xsi:type="boolean">false</item>
</item>

1 Answer 1

39

You can use validate-digits for validating number

<item name="validation" xsi:type="array">
    <item name="validate-digits" xsi:type="boolean">true</item>
</item>

Here is the list of validation which you can use in UI form

min_text_length
max_text_length
max-words
min-words
range-words
letters-with-basic-punc
alphanumeric
letters-only
no-whitespace
zip-range
integer
vinUS
dateITA
dateNL
time
time12h
phoneUS
phoneUK
mobileUK
stripped-min-length
email2
url2
credit-card-types
ipv4
ipv6
pattern
validate-no-html-tags
validate-select
validate-no-empty
validate-alphanum-with-spaces
validate-data
validate-street
validate-phoneStrict
validate-phoneLax
validate-fax
validate-email
validate-emailSender
validate-password
validate-admin-password
validate-url
validate-clean-url
validate-xml-identifier
validate-ssn
validate-zip-us
validate-date-au
validate-currency-dollar
validate-not-negative-number
validate-zero-or-greater
validate-greater-than-zero
validate-css-length
validate-number
validate-number-range
validate-digits
validate-digits-range
validate-range
validate-alpha
validate-code
validate-alphanum
validate-date
validate-identifier
validate-zip-international
validate-state
less-than-equals-to
greater-than-equals-to
validate-emails
validate-cc-number
validate-cc-ukss
required-entry
checked
not-negative-amount
validate-per-page-value-list
validate-new-password
validate-item-quantity
equalTo
4
  • The link provided redirects you to the website's blog lister page instead of the post itself because the URL has been updated. Within the blog post itself, it states that you can view the logic in the validation.js file, with a link to Magento's file in GitHub, but this shows a 404; that URL has also been updated.
    – Smithee
    Commented Jun 10, 2020 at 10:10
  • @Smithee Thanks for the update. Url is github.com/magento/magento2/blob/2.3/lib/web/mage/validation.js i will update in blog soon. Commented Jun 10, 2020 at 11:25
  • @PrincePatel no problem! I didn't realise it was your actual blog post! You're right the URL is that with "develop", I just changed the version number as I know 2.4 is now in development.
    – Smithee
    Commented Jun 10, 2020 at 13:58
  • 1
    @anonymous I'm not sure if there's a Regex-less method, but this should work: <item name="pattern" xsi:type="string">^\d+(\.\d{1,2})?$</item>. The pattern says, "match a string where at the start is one or more consecutive digits, optionally followed by a decimal point, to which then between one and two digits must follow afterwards".
    – Smithee
    Commented Jun 10, 2020 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.