Skip to content

Commit c54b8f3

Browse files
committed
Validate phone field on checkout page
1 parent 1116437 commit c54b8f3

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontOnePageCheckoutPhoneValidationTest">
12+
<annotations>
13+
<features value="Checkout"/>
14+
<stories value="Checkout validation phone field"/>
15+
<title value="Validate phone field on checkout page"/>
16+
<description value="Validate phone field on checkout page, field must not contain alphabetical symbols"/>
17+
<severity value="MAJOR" />
18+
</annotations>
19+
<before>
20+
<createData entity="_defaultCategory" stepKey="createCategory"/>
21+
<createData entity="ApiSimpleProduct" stepKey="createProduct">
22+
<requiredEntity createDataKey="createCategory"/>
23+
</createData>
24+
</before>
25+
<after>
26+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
27+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
28+
</after>
29+
30+
<actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="openCategoryPageOnFrontend">
31+
<argument name="category" value="$createCategory$"/>
32+
</actionGroup>
33+
34+
<actionGroup ref="StorefrontAddSimpleProductToCartActionGroup" stepKey="addToCartFromStorefrontProductPage">
35+
<argument name="product" value="$$createProduct$$"/>
36+
</actionGroup>
37+
38+
<actionGroup ref="StorefrontOpenCheckoutPageActionGroup" stepKey="guestGoToCheckout"/>
39+
40+
<fillField userInput="Sample text" selector="{{CheckoutShippingSection.telephone}}" stepKey="enterAlphabeticalSymbols"/>
41+
<see userInput="Please enter a valid phone number. For example (123) 456-7890, 123-456-7890, +(123)4567890, +1234567890" selector="{{CheckoutShippingSection.addressFieldValidationError}}" stepKey="checkPhoneFieldValidationIsPassed"/>
42+
</test>
43+
</tests>

app/code/Magento/Checkout/view/frontend/layout/checkout_index_index.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@
223223
</item>
224224
</item>
225225
<item name="telephone" xsi:type="array">
226+
<item name="validation" xsi:type="array">
227+
<item name="validate-phone" xsi:type="number">0</item>
228+
</item>
226229
<item name="config" xsi:type="array">
227230
<item name="tooltip" xsi:type="array">
228231
<item name="description" xsi:type="string" translate="true">For delivery questions.</item>

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,13 @@ define([
432432
},
433433
$.mage.__('Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.')
434434
],
435+
'validate-phone': [
436+
function (value) {
437+
return utils.isEmptyNoTrim(value) ||
438+
/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$/.test(value);
439+
},
440+
$.mage.__('Please enter a valid phone number. For example (123) 456-7890, 123-456-7890, +(123)4567890, +1234567890')
441+
],
435442
'validate-fax': [
436443
function (value) {
437444
return utils.isEmptyNoTrim(value) || /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/.test(value);

0 commit comments

Comments
 (0)