Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Stripe elements postal code that accepts UK postcodes?

I'm creating a payment form with separate Stripe Elements:

var stripe = Stripe(...);
var elements = stripe.elements();
...
var postalCode = elements.create('postalCode');
postalCode.mount('#postalCode');

This creates a field that accepts only digits. However, the UK's post codes contain letter as well. How do I allow these too? I want the user to be able to input pretty much any possible post code in the world.

like image 494
Vedran Šego Avatar asked Apr 21 '17 15:04

Vedran Šego


People also ask

How do you write a UK postal code?

It consists of a numeric character followed by two alphabetic characters. The numeric character identifies the sector within the postal district. The alphabetic characters then define one or more properties within the sector. For example: PO1 3AX PO refers to the postcode area of Portsmouth.

Does stripe require postal code?

Stripe Tax supports calculating sales tax with only a basic 5-digit US postal code. The country field must be the ISO country code “US”.

How do you write a valid postcode?

Postcodes should always be in BLOCK CAPITALS as the last line of an address. Do not underline the postcode or use any punctuation. Leave a clear space of one character between the two parts of the postcode and do not join the characters in any way.

What datatype is postcode?

The right data type for a postal code is a string. In a SQL database, this would typically be VARCHAR() or CHAR() , of the appropriate length.


Video Answer


1 Answers

As mentioned in comments, the form dynamically adjusts based on the card you enter, since the card indicates its country. However, it doesn't seem to validate effectively. I was able to create a valid test order with invalid UK postcode.

Stripe has test card numbers for many countries. Try entering them into your Elements forms.

Form when user types Stripe's generic (US) test Visa card shows "ZIP" (it shows ZIP when empty too):

Form with Stripe's generic (US) Visa card

The same form when user types in Stripe's test UK Visa card changes to showing "Postcode" during typing:

Form with Stripe's UK test card

like image 102
mahemoff Avatar answered Oct 14 '22 02:10

mahemoff