JSFiddle - React, Tailwind, and code Playground

by mahassan

JavaScript

let postcode = "BB10 1BX"
let reg = /^((GIR 0AA)|((([A-PR-UWYZ][A-HK-Y]?[0-9][0-9]?)|(([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRV-Y]))) [0-9][ABD-HJLNP-UW-Z]{2}))$/

let match = reg.test(postcode);

if(match){
console.log("correct");
}else{
console.log("false");
}