JSFiddle - React, Tailwind, and code Playground
by davidmurdoch
HTML
<input id="Text1">
<button>Format It!</button>
JavaScript
var FormatDutchPostalCode = (function() {
var reg = /^([1-9]\d{3})\s?([a-zA-Z]{2})$/;
return function(){
var postcode = $.trim($("#Text1").val());
if (postcode && postcode.match(reg) )
{
return postcode.replace(reg, "$1$2").toUpperCase();
}
else
{
throw new Error("Postcode incorrect");
}
};
}());
$("button").click(function(e){
e.preventDefault();
alert( FormatDutchPostalCode() );
});