I have copied it from my code, please feel free to change it as required.

let usZipPattern = new RegExp("^\\d{5}(-{0,1}\\d{4})?$");
let caZipPattern = new RegExp(/([ABCEGHJKLMNPRSTVXY]\d)([ABCEGHJKLMNPRSTVWXYZ]\d){2}/i);
let postal = frm.find( '#postal' );
let postalValue = $.trim( postal.val() );
if( 
    postalValue.length == 0 ||
    ( country == 'US' && !usZipPattern( postalValue ) ) ||
    ( country == 'CA' && !caZipPattern( postalValue.replace( /\W+/g, '' ) ) )
) {
    postal.addClass( 'form-error' ).focus();
    hasError = true;
}