JSFiddle - React, Tailwind, and code Playground
by Christian Juth
JavaScript
parseNumber = function (txt) {
txt = txt.replace(/(\s|,|\.)/ig, '');
txt = txt.replace(/thousand/ig, '000');
txt = txt.replace(/hundred$/ig, '00');
txt = txt.replace(/hundred/ig, '');
txt = txt.replace(/ten/ig, '10');
txt = txt.replace(/twenty/ig, '20');
txt = txt.replace(/thirty/ig, '30');
txt = txt.replace(/forty/ig, '40');
txt = txt.replace(/fifty/ig, '50');
txt = txt.replace(/sixty/ig, '60');
txt = txt.replace(/seventy/ig, '70');
txt = txt.replace(/eighty/ig, '80');
txt = txt.replace(/ninety/ig, '90');
txt = txt.replace(/one/ig, '1');
txt = txt.replace(/two/ig, '2');
txt = txt.replace(/three/ig, '3');
txt = txt.replace(/four/ig, '4');
txt = txt.replace(/five/ig, '5');
txt = txt.replace(/six/ig, '6');
txt = txt.replace(/seven/ig, '7');
txt = txt.replace(/eight/ig, '8');
txt = txt.replace(/nine/ig, '9');
txt = txt.replace(/ten/ig, '0');
return txt;
}
alert(parseNumber('two thousand'));