为 magento 2.1.4 网站中存在的所有 phone 数字字段添加自定义 phone 数字验证
Custom phone number validation add for all phone number fields present in the site in magento 2.1.4
找不到正确的文件名和添加验证码的过程。 我正在尝试为 phone 数字字段添加验证,即检查所有号码,并根据国家代码检查是否正确。
step1) 在vendor\magento\module-checkout\view\frontend\layout\checkout_index_index.xml
中添加如下内容
<item name="telephone" xsi:type="array">
<item name="validation" xsi:type="array">
<item name="testPhone" xsi:type="string">true</item>
</item>
</item>
step2) 在vendor\magento\magento2-base\lib\web\mage\validation.js
中添加如下内容
"testPhone": [
function (phone_number, element) {
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/([+]?\d{1,2}[.-\s]?)?(\d{3}[.-]?){2}\d{4}/g) &&
phone_number.match(/^[-+]?[0-9]+$/);
},
'Please specify a valid mobile number'
],
step3) 在vendor\magento\module-ui\view\base\web\js\lib\validation\rules.js
中添加如下内容
"testPhone": [
function(value) {
return value.length > 9 && value.match(/([+]?\d{1,2}[.-\s]?)?(\d{3}[.-]?){2}\d{4}/g) && value.match(/^[-+]?[0-9]+$/);
},
$.mage.__('Please specify a valid mobile number')
],
找不到正确的文件名和添加验证码的过程。 我正在尝试为 phone 数字字段添加验证,即检查所有号码,并根据国家代码检查是否正确。
step1) 在vendor\magento\module-checkout\view\frontend\layout\checkout_index_index.xml
中添加如下内容<item name="telephone" xsi:type="array">
<item name="validation" xsi:type="array">
<item name="testPhone" xsi:type="string">true</item>
</item>
</item>
step2) 在vendor\magento\magento2-base\lib\web\mage\validation.js
中添加如下内容"testPhone": [
function (phone_number, element) {
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/([+]?\d{1,2}[.-\s]?)?(\d{3}[.-]?){2}\d{4}/g) &&
phone_number.match(/^[-+]?[0-9]+$/);
},
'Please specify a valid mobile number'
],
step3) 在vendor\magento\module-ui\view\base\web\js\lib\validation\rules.js
中添加如下内容"testPhone": [
function(value) {
return value.length > 9 && value.match(/([+]?\d{1,2}[.-\s]?)?(\d{3}[.-]?){2}\d{4}/g) && value.match(/^[-+]?[0-9]+$/);
},
$.mage.__('Please specify a valid mobile number')
],