<input id = "#guilty" /> <button id = "#check" >check</button> <script type = "text/javascript"> document.getElementById("#check").onclick = function () { alert(/^\s*[\d]+(?:,[\d]+)?\s*$/.test(document.getElementById("#guilty").value) ); } </script>