#Swann - postal code
1 messages ยท Page 1 of 1 (latest)
Hey! Long time no see
Sure
I'm trying to find a way to validate the postal code after getting it back from the react native sdk
I've found this code in the android sdk that seems useful
internal enum class Config {
Global,
US
}
/**
* Returns if the postal is valid. If config is not US, any non-empty postal is valid.
*/
internal fun hasValidPostal() =
config == Config.US && ZIP_CODE_PATTERN.matcher(fieldText)
.matches() || 1eldText.isNotEmpty()
private companion object {
private const val MAX_LENGTH_US = 5
private val ZIP_CODE_PATTERN = Pattern.compile("^[0-9]{5}$")
}
But I still need to check the address_postal_code_check field before creating the card
Oh ok. So what is happening in that screenshot? Is that not validating the postal code prior to creating the card?
So this screenshot is of the PaymentSessions screen from the native sdk (iOS in this instance)
We're migrating over from using the native sdks directly to using the react native sdk
The native sdk handled postal code validation correctly (including taking into account stripe fraud settings)
But now that I've rewritten it to use the react native sdk we're missing the ability to do that ๐ฆ
Got it. Let me check with a colleague on this
So the recommendation I got for this is to add validation yourself based on the onCardChange CardField method
I agree
Is there a way for me to know which country the card is from for me to do the postal code validation?
๐ Hello! Just stepping in since @regal loom has to head out - quick question, what are you using in the react native sdk? payment element?
๐ What specific part of the react native sdk are you using though, payment sheet? just the card element?
Sorry! I'm using the CardField component Ref :: https://stripe.dev/stripe-react-native/api-reference/index.html#CardField
I believe this is the same as the card element from the web sdk?
Gotcha, and because the ReactNative CardField doesn't provide postal code validation right now, you're asking how to get the country so you can do the validation yourself?
Yes! ๐
I don't think there's a way for you to get that (and I wouldn't recommend it even if you could, since a common issue that you see in the web card element is that the country tied to the card doesn't match the country of their billing address). You should collect the billing address country in a separate UI and validate off that