Haga coincidir el patrón en la entrada con JavaScript

var elem = document.getElementById("Cpostalcode");

var pattern = elem.getAttribute("pattern");
var re = new RegExp(pattern);
if (re.test(elem.value)) {
    // Pattern matches!
} else {
    // Pattern does NOT match.
}
Marwen Labidi