filmov
tv
How to Validate a Postcode Using Kotlin

Показать описание
How to Validate a Postcode Using Kotlin
Greetings, in this tutorial we shall be covering how to validate a postcode using Kotlin. One method of doing this is to use a regex (regular expression) pattern.
We can define a set of rules using a regex pattern and then check this against a user input to check if the postcode matches the set of rules defined in the regex pattern.
This also makes validating postcodes from other countries easy as we can just swap the valid postcode regex patterns.
Line of Kotlin code with UK postcode regex used in this tutorial:
val regex = Regex("^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})\$")
Copy and paste the above Kotlin code.
Thanks for watching this Kotlin tutorial on how to validate a postcode.
Subscribe to keep notified when I upload?:
How to Validate a Postcode Using Kotlin
Greetings, in this tutorial we shall be covering how to validate a postcode using Kotlin. One method of doing this is to use a regex (regular expression) pattern.
We can define a set of rules using a regex pattern and then check this against a user input to check if the postcode matches the set of rules defined in the regex pattern.
This also makes validating postcodes from other countries easy as we can just swap the valid postcode regex patterns.
Line of Kotlin code with UK postcode regex used in this tutorial:
val regex = Regex("^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))[0-9][A-Za-z]{2})\$")
Copy and paste the above Kotlin code.
Thanks for watching this Kotlin tutorial on how to validate a postcode.
Subscribe to keep notified when I upload?:
How to Validate a Postcode Using Kotlin