JSFiddle - React, Tailwind, and code Playground

by Hui Zheng

JavaScript

var matches = [
  ".1", ".11",  "0.11",  "10.", "10.1",   "10.12",  "00.00",  "0.0",  "00.00",
"123456", "12345", "1234", "123", "12", "1", "0", "0.", "123.", "123.55", "123456." 
  ],
    
fails = ["", ".", "123..", "1a"],
regex = /^(?!\.?$)\d{0,6}(\.\d{0,2})?$/,
pad = "        ";

document.write("<pre>MATCH:<br/>");
matches.forEach(testMatch, true);
document.write("<br/>FAIL:<br/>");
fails.forEach(testMatch, false);
document.write("</pre>");


function testMatch(str) {
    document.write(pad.substr(0, pad.length - str.length) + str
                  + " => " + (str.match(regex)? "match" : "fail") + "<br/>");
}