var regex = /[A-Za-z]\\d[A-Za-z] ?\\d[A-Za-z]\\d/;
var match = regex.exec(value);
if (match){
if ( (value.indexOf(\"-\") !== -1 || value.indexOf(\" \") !== -1 )
This is a function that will do everything for you in one shot. Accepts AAA BBB and AAABBB with or without space.
function go_postal(){
let postal = $("#postal").val();
var regex = /^[A-Za-z]\d[A-Za-z][ -]?\d[A-Za-z]\d$/;
var pr = regex .test(postal);
if(pr === true){
//all good
} else {
// not so much
}
}