Ignore Case and Spaces
Compare text values and ignore differences in capital letters, spaces and light punctuation. Use it to check that the checkout address is the address that the customer entered in the cart.
Overview
Four condition operators compare text and ignore letter case, spaces and light punctuation:
- Equals (ignore case and spaces)
- Does not equal (ignore case and spaces)
- Contains (ignore case and spaces)
- Does not contain (ignore case and spaces)
With these operators, SW1A 1AA equals sw1a1aa, and Flat 2, 12 High St. equals flat 2 12 high st. All other differences count. Ana does not equal Anna.
Use cases:
- Block checkout when the shipping address is not the gift recipient that the customer entered in the cart. Apple Pay and Google Pay can replace that address with the buyer’s saved address.
- Compare a postal code, a name or a company with a value from a cart attribute or a metafield, when customers type it in different ways.
- Match a code or a reference number that customers type with spaces or in lowercase.
Availability
The operators are available for text conditions in:
- Validation functions
- Delivery Customization functions
- Payment Customization functions
They are not available in Discount, Cart Transform or promotion flows.
Note
The operators need the latest version of the app’s functions. A function that was saved with an older app version keeps its old logic until you save it again.
Setup
Compare a field with a fixed value
Add a condition
In a Check if… block, select the text field, for example Delivery Address: ZIP Code.
Select the operator
Select one of the four operators, for example Equals (ignore case and spaces).
Enter the value
Type the value. Case and spaces in the value do not matter.
Compare two fields
Open the variable list
In a condition, open the variable list and select Advanced Condition.
Select the scope
Select Cart-level (entire order).
Select the first field
For example, a cart attribute.
Select the operator
Select equals, ignore case and spaces (~=), not equals, ignore case and spaces (!~=), contains, ignore case and spaces (~*=) or does not contain, ignore case and spaces (!~*=).
Select the second field
For example, Delivery Address: First Name.
Join two fields
Wallets and customers split names and addresses in different ways. Join the parts before you compare them.
Select a text field
In an Advanced Condition, select the first part, for example Delivery Address: First Name.
Join the next part
Select join text (+) and the next part, for example Delivery Address: Last Name.
Compare
Select a loose operator and the value to compare with. You can join fields on both sides.
With a join, Welch + Wallet Test equals Welch Wallet + Test. A part that has no value joins as an empty text.
Note
Joining fields works in validations and payment customizations. In delivery customizations, compare single fields.
How It Works
Spaces
All spaces are removed before the comparison: spaces at the start and the end, spaces in the middle, tabs, line breaks, and the no-break spaces that copied text can contain.
Warning
Spaces are removed everywhere. So 1 23 High St equals 12 3 High St. If the position of a space matters, use Equal or Not equal.
Letter case
Capital and small letters are equal in the Latin, Greek and Cyrillic alphabets, accented letters included (ÉLAN equals élan).
These letters are not made equal: ß and ss, the Turkish İ and ı, and the same accented letter typed in two different ways. They count as different.
Punctuation
Periods, commas and apostrophes are ignored: 68, Wellington St. equals 68 Wellington St, and O'Neil equals ONeil.
Hyphens, slashes, # and other characters count. 12-14 does not equal 1214.
Warning
Abbreviations are not equal. St does not equal Street.
Contains
Contains (ignore case and spaces) is true when the first value includes the second value, after the same rules. Use it when a value can move between fields. For example, the checkout’s Address line 1 and Address line 2 joined contain Flat 2, 10 High St when a wallet puts Flat 2 on line 1 and 10 High St on line 2.
Empty values
A field that has no value is equal to an empty text. For example, an empty Address line 2 in the cart and a missing Delivery Address Line 2 in checkout are equal.
Numbers
A number compares as its digits. 90210 equals "90210".
Tip
Save postal codes and other codes as text, not as numbers. A number loses its leading zeros: 01234 becomes 1234.
Examples
Keep the gift recipient’s address
A florist saves the recipient’s details in a cart attribute. Apple Pay and Google Pay can replace the shipping address with the buyer’s own address. The validation blocks the order when the checkout name or destination is not the recipient’s, and accepts a different name split or address layout.
Save the recipient in one cart attribute
In your cart page, save the recipient’s details as JSON in one cart attribute, for example recipient = {"first_name":"Ana","last_name":"Silva","address1":"12 High St","address2":"","city":"London","zip":"SW1A 1AA","country":"GB"}. Save all values as text.
Create a validation
Create a validation function and add a Check if… block.
Add the guards
Add Cart Attribute recipient Is not blank. To skip collections, add Selected Delivery Option Title Does not include and a word from your collection option’s title.
Compare the name
Add an Advanced Condition: first_name join text (+) last_name of the recipient attribute (type JSON, JSON Key) not equals, ignore case and spaces (!~=) Delivery Address: First Name join text (+) Delivery Address: Last Name.
Compare the street
Add an Advanced Condition: Delivery Address Line 1 join text (+) Delivery Address Line 2 does not contain, ignore case and spaces (!~*=) the recipient’s address1.
Compare the postcode and country
Compare zip with Delivery Address: ZIP Code and country with Delivery Address: Country, with not equals, ignore case and spaces (!~=). The town, county and company are not compared, because wallets often put a different town on these lines.
Fail the validation
Connect each comparison to a Fail validation block with a clear message and an Error placement on that field, for example “The postcode must be the recipient’s postcode. Change it here, or change the recipient in your basket.”
Run it at checkout completion
In each Fail validation block, select only Checkout Completion in Buyer journey.
Warning
Select only Checkout Completion. Apple Pay and Google Pay give only the country, province, city and postal code before the customer confirms the payment. The full address is available only at checkout completion.
Note
One validation function reads one cart attribute. Put all the recipient’s details in one JSON attribute. The Delivery Address: First Name and Delivery Address: Last Name fields are available in the Delivery focused input.
Apple Pay and Google Pay for gift orders
The validation stops the wrong order, but it cannot fix the wallet:
- The Apple Pay sheet uses the buyer’s saved contact. No app can put the cart’s recipient into it.
- The wallet shows “Payment failed”. The validation message appears on the checkout page after that.
- Each new Apple Pay attempt uses the wallet contact again.
For orders with a recipient, send customers through the normal checkout:
Hide the wallets
Create a payment customization that hides Apple Pay and Google Pay when Cart Attribute recipient Is not blank. On stores without Shopify Plus, this removes the wallet from every place in checkout.
Remove the express buttons
In the theme, turn off the dynamic checkout buttons on product and cart pages.
Prefill the address
In the cart, add the recipient as the selected delivery address of the cart (Storefront API mutation cartDeliveryAddressesAdd with selected: true and oneTimeUse: true). Checkout then opens with the recipient’s address.
Keep the validation
It still blocks an order with a different recipient.
Postal code from a metafield
Block delivery to a postal code that is saved in a customer metafield, in any format:
Add the condition
Add an Advanced Condition: the customer metafield equals, ignore case and spaces (~=) Delivery Address: ZIP Code.
Add the action
Connect the condition to the action that you need, for example Fail validation.
Important Considerations
- Only the first delivery group is checked. Split shipments are not compared.
- Cart attribute conditions need the Standard plan or higher. Advanced Conditions are not available on the Free plan.
- For pattern matching (for example “contains a P.O. Box”), use Regular Expressions.
Troubleshooting
Every order is blocked
- Make sure that the condition Cart Attribute
recipientIs not blank comes first. - Make sure that the attribute value is JSON and that each JSON Key matches a key in it, for example
first_name. - Make sure that Fail validation runs only at Checkout Completion.
A correct address is blocked
- Compare the joined name, not the first name and last name one by one.
- Compare the street with does not contain, ignore case and spaces (!~*=) against Delivery Address Line 1 joined with Delivery Address Line 2.
- Check for abbreviations, for example
StandStreet. They count as different.
A different address is not blocked
- Join the field conditions with OR, or use one branch per field, so that one different field blocks the order.
- Save the function again after you update the app. A function that was saved earlier keeps its old logic.