I have some client-side validation in a text box that resolves numbers up to two decimal places without another input.
This script was the base for entering numeric values, but it needs to be adapted so that it can accept a decimal point, followed only by two decimal places.
I tried things like /[^\d].\d{0,2} , but then replacing the call did not work, and I have no idea how to do this.
the code
<script type="text/JavaScript"> function valid(f) { if (!/^\d*$/.test(f.value)) { f.value = f.value.replace(/[^\d]/g,""); alert("Invalid number"); } } </script>
Note
I need to match an empty string. If an empty string is provided and the form is submitted, the default value returns to zero.
javascript regex
Kezzer Jan 22 '09 at 10:46 2009-01-22 10:46
source share