-
Notifications
You must be signed in to change notification settings - Fork 659
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
Add postal validation #5456
Add postal validation #5456
Conversation
06251fc
to
aaf6d54
Compare
aaf6d54
to
3b66ec4
Compare
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.
Works well! Just a few comments with UX improvement ideas.
SimpleTextFieldController( | ||
val textFieldConfig = when (it) { | ||
FieldType.PostalCode -> { | ||
addressField.schema?.nameType |
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.
Can this be removed?
object CA : CountryPostalFormat( | ||
minimumLength = 6, | ||
maximumLength = 6, | ||
regexPattern = Regex("([a-zA-Z]\\d)+") |
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.
Should we allow spaces for Canadian postal codes? Currently, it’s not possible to enter them.
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.
And another 🇨🇦 question: Should we auto-capitalize the postal code? I find a1b 2c3
looks odd, and A1B 2C3
looks much nicer.
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.
Added spacing regex, won't fix the auto-capitalization
Added through visual transformation
override fun filter(userTyped: String): String = | ||
if ( | ||
setOf(KeyboardType.Number, KeyboardType.NumberPassword).contains(keyboard) | ||
) { | ||
userTyped.filter { it.isDigit() } | ||
} else { | ||
userTyped | ||
}.replace(Regex("\\s*"), "") |
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.
On iOS, it looks like we restrict the input length to the country’s maximum length. Can we do the same here?
3b66ec4
to
db98039
Compare
db98039
to
507accf
Compare
maximumLength = 9, | ||
regexPattern = Regex("\\d+") | ||
) | ||
object Other : CountryPostalFormat( |
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.
Is this copied from stripe.js or somewhere else? Just making sure we're not being too strict on the requirements. Better to not validate than to validate it wrong and end up not accepting a valid value, which frustrates the user.
val maximumLength: Int, | ||
val regexPattern: Regex | ||
) { | ||
object CA : CountryPostalFormat( |
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.
Since you're accepting the space, should it take up to 7 characters now?
maximumLength = 6, | ||
regexPattern = Regex("[a-zA-Z]\\d[a-zA-Z][\\s-]?\\d[a-zA-Z]\\d") | ||
) | ||
object US : CountryPostalFormat( |
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.
Usually a 9-digit zip code is formatted as 12345-6789.
This and the spaces for CA would be better handled by a VisualTransformation
, like we have for the card number and others. For these two it would be a pretty simple one, I think it's worth taking a look.
Summary
Validate the postal code in payment sheet
Motivation
Testing
Screenshots
Changelog