Customize the address fields validation of commercetools Checkout
Customize the validation rules for the address fields in your checkout experience.
commercetools Checkout lets you customize the frontend validation rules for the shipping and billing address fields of your checkout experience.
You can customize the validation rules according to your needs to obtain accurate address data. This way, you can reduce errors related to address entry by your customers.
If the billing and shipping address forms contain the same field, the customization applies to both forms. For example, if you customize the validation rules of the
firstName field, the rules will apply for the field on both the billing and shipping address forms.
Address fields validation is a frontend validation only.
Following are the default validation rules for the address fields. For information on the customization of the validation rules, see the following customization examples.
Default validation rules for address fields
|Yes||See Default postal code validations patterns.||-|
For information on field label customization, see Texts and labels.
Default postal code validation patterns
Default error messages
|A required field was not filled in.||Required field|
|The postal code entered does not meet the default validation pattern.||Invalid ZIP Code|
|The email address entered does not meet the default validation pattern.||Invalid email address|
|The phone number entered does not meet the default validation pattern.||Invalid phone number|
For information on message customization, see Texts and labels.
Deactivate default validation rules for all fields
You can deactivate the default validation rules for all address fields by setting
Deactivate default validation rules for one field
You can deactivate the default validation rule for a specific field by setting
true. The following example deactivates the default validation rule for the
Set minimum and maximum length of a field
You can set the minimum and/or maximum length for a field with the
minLength validation rules. The following example sets the minimum length of the
phone field to five characters and its maximum length to ten.
Make a field required or optional
You can set a field as required or optional with the
required validation rule. The following example sets the
phone field as required.
Set the validation pattern for a field
You can set the validation pattern for a field with the
pattern validation rule. The following example sets a validation pattern for the
firstName field so that it accepts only capital letters as the first letter.
Set validation error messages
message validation rule, you can set error messages to be displayed if the value entered into a field does not meet its validation rule. The following example sets the error message that appears if the value entered in the
firstName field does not begin with a capital letter.