Smixen
Smixen

Reputation: 51

How to check if address written in correct structure PHP

How do I check if an adress is written in a correct structure.

Let's say I got a table like this..

ID - Name - Email - Adress

1 - John - [email protected] - Exampleroad 10, 123 45 City

2 - John2 - [email protected] - Exampleroad 12-14, 123 45 City

3 - John3 - [email protected] - Exampleroad 106, 123 45 City

4 - John4 - [email protected] - Exampleroad 33

5 - John5 - [email protected] - Exampleroad 16 123 45 City

6 - John6 - [email protected] - Exampleroad, 123 45 City


ID 4,5 and 6 are incorrect, 

Is their anyway to check this?

ID 4: MISSING, ZIP AND CITY

ID 5: MISSING COMMA

ID 6: MISSING ROADNUMBER

Upvotes: 0

Views: 83

Answers (1)

Hazonko
Hazonko

Reputation: 1035

Multipart fields should always be separated into their own fields as a best practice. This is so you can check each part of the address to be correct, but also be able to use each part of the data individually if needed.

You should split out your address into multiple columns.

AddressLine1 AddressLine2 Town State Postcode

Can obviously also add 3rd line of address and country if needed.

Upvotes: 2

Related Questions