<meta name="viewport" content="width=device-width">
<form onsubmit="onsubmit(event)">
<div>ZIP (US or CA)</div>
<div>US Format: nnnnn or nnnnn-nnnn</div>
<div>CA Format: A0A 0A0</div>
<input id='ipt' type="text" required pattern="(\d{5}([\-]\d{4})?)|[A-Za-z][0-9][A-Za-z] [0-9][A-Za-z][0-9]" placeholder='ZIP'/>
<button type=submit>⮐</button>
<script id="jsbin-javascript">
var ipt = document.getElementById('ipt');
var el = document.getElementById('div').innerHTML = ipt.value + ' matches the US or CA postal code pattern';
<script id="jsbin-source-css" type="text/css">body{
<script id="jsbin-source-javascript" type="text/javascript">function onsubmit(e){
var ipt = document.getElementById('ipt');
var el = document.getElementById('div').innerHTML = ipt.value + ' matches the US or CA postal code pattern';