Validating a Postcode in Java

preview_player
Показать описание
Hello guys and girls, today I am here with postcode validation to help you get that A in your practical exam. I will be honest, most tutorials out there for this are too long or are terrible so I hope I break the trend and provide a useful video. All you do is get the user input, make a pattern object, compare the user input to the patter. If it matches the rule of the pattern (aka regex) then print true, if not then print false.

Regex code: "^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$"

Easter holidays are over but I will try to upload as often as possible. Why not subscribe to keep notified when I upload?

Social media:

Validating a Postcode in Java
Рекомендации по теме
Комментарии
Автор

Hey Max, thanks for the free educational video coming from a student. I have a question for validating a postal code. Can you please explain how you came up with this exact pattern ( "^[A-Z]{1, 2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$")? I want to use regex to validate a Dutch postal code that contains of 4 numbers and then two letters (for example 1095 LD), but I don't understand how to change the format so it can validate a Dutch postal code.

Kind regards.

itsme-iwsk