最大长度的邮政编码验证

时间:2018-07-20 08:09:58

标签: magento2.2

我正在使用Magento 2.2,邮政编码验证不起作用。 编码第1部分:

"validate-zip-in": [
            function(value) {
                return utils.isEmptyNoTrim(value) || /(^\d{6}$)/.test(value);

            },
            $.mage.__('Please enter a valid zip code (Ex: 123456).')
        ],

编码第2部分:checkout_index_index.xml

     </item>
                            <item name="validation" xsi:type="array">
                                                                    <item name="validate-digits" xsi:type="string">true</item>
                                                            </item>  
                            <item name="validation" xsi:type="array">
                                    <item name="validate-zip-in" xsi:type="string" pattern="[0-9]*" max-length="6">true</item>
                                <item name="zip-range" xsi:type="string">6</item>
                            </item> `

但是它不起作用。我想为India验证最大长度为“ 6”。请尽快答复

1 个答案:

答案 0 :(得分:0)

示例

$fieldset->addField(
    'email_from',
    'text',
    ['name' => 'email_from', 'label' => __('Email From'), 'title' => __('Email From'), 'required' => true, 'class' => 'validate-email']
);

上面提到的是一种示例格式,您可以添加以下任何类以进行验证

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 

尝试使其变得简单,只需添加css类即可应用规则。

您可以使用范围限定符{min,max}将最小1位数字和最大6位数字指定为:

^[0-9]{1,6}$

^     : Start anchor
[0-9] : Character class to match one of the 10 digits
{1,6} : Range quantifier. Minimum 1 repetition and maximum 6.
$     : End anchor

面对面的^[0-9]{6}$