Aessandro
Aessandro

Reputation: 5771

jQuery postcode validation space required

The following line of code works well to check a postcode format. However it doesn't allow to use space in between:

var postMatch = /[A-z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}/i;

This would be correct: se34tyu

This one no: se34 tyu

What can I add to make that happen?

Full code

Upvotes: 1

Views: 1334

Answers (1)

techfoobar
techfoobar

Reputation: 66693

Use \s* for allowing an optional space.

/[A-z]{1,2}[0-9]{1,2}\s*[0-9][A-Z]{2}/i

Upvotes: 2

Related Questions