-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Add validation phone field on checkout page #27537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c54b8f3
196e423
f951152
f5c2575
42889f8
d9f626d
9706369
0433c82
3afe988
15ceda0
a692863
95be243
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
|
||
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> | ||
<test name="StorefrontOnePageCheckoutPhoneValidationTest"> | ||
<annotations> | ||
<features value="Checkout"/> | ||
<stories value="Checkout validation phone field"/> | ||
<title value="Validate phone field on checkout page"/> | ||
<description value="Validate phone field on checkout page, field must not contain alphabetical symbols"/> | ||
<severity value="MAJOR" /> | ||
</annotations> | ||
<before> | ||
<createData entity="_defaultCategory" stepKey="createCategory"/> | ||
<createData entity="ApiSimpleProduct" stepKey="createProduct"> | ||
<requiredEntity createDataKey="createCategory"/> | ||
</createData> | ||
</before> | ||
<after> | ||
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/> | ||
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/> | ||
</after> | ||
|
||
<actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="openCategoryPageOnFrontend"> | ||
<argument name="category" value="$createCategory$"/> | ||
</actionGroup> | ||
|
||
<actionGroup ref="StorefrontAddSimpleProductToCartActionGroup" stepKey="addToCartFromStorefrontProductPage"> | ||
<argument name="product" value="$$createProduct$$"/> | ||
</actionGroup> | ||
|
||
<actionGroup ref="StorefrontOpenCheckoutPageActionGroup" stepKey="guestGoToCheckout"/> | ||
|
||
<fillField userInput="Sample text" selector="{{CheckoutShippingSection.telephone}}" stepKey="enterAlphabeticalSymbols"/> | ||
<see userInput="Please enter a valid phone number. For example (123) 456-7890, 123-456-7890, +(123)4567890, +1234567890" selector="{{CheckoutShippingSection.addressFieldValidationError}}" stepKey="checkPhoneFieldValidationIsPassed"/> | ||
</test> | ||
</tests> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -432,6 +432,13 @@ define([ | |||||
}, | ||||||
$.mage.__('Please enter a valid phone number. For example (123) 456-7890 or 123-456-7890.') | ||||||
], | ||||||
'validate-phone': [ | ||||||
function (value) { | ||||||
return utils.isEmptyNoTrim(value) || | ||||||
/^[+]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$/.test(value); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to my tests, the slash has to be escaped:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have fixed it. |
||||||
}, | ||||||
$.mage.__('Please enter a valid phone number. For example (123) 456-7890, 123-456-7890, +(123)4567890, +1234567890') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static tests are failing because of this line length, can you please break it into multiple lines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by add |
||||||
], | ||||||
'validate-fax': [ | ||||||
function (value) { | ||||||
return utils.isEmptyNoTrim(value) || /^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/.test(value); | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding yet another validation rule to
validate-phoneStrict
andvalidate-phoneLax
seems a bit redundant. I'd use one of the existing ones and expand them if necessary.It also feels like something that can be easily confusing in the future when someone needs one of the validation rules and asks "what is the difference between them?".
Because there are two validation rules for phone numbers maybe it'd be good to add a configuration to specify whether to allow for "lax" validation or rather the more "strict" one (depending on the wants of the end-user).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Usik2203 This is a very apt comment. Please can you consider it.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Serializator , @engcom-Echo
I will check it. Thank you for advice!