Click to See Complete Forum and Search --> : Regular Expression for decimal value with "," and "."


shanuragu
09-03-2003, 08:15 AM
Hi

Can any one give me a regular expression for a decimal field with following conditions.

1. Only numbers
2. Allow "." and/or "," OR both only once
3. "," is alowed only when the number is >= 1000
4. only two zeros are allowed after decimal point

ex:
1,245/100.25/1,800.00/16,700/1200/1300.78

shara

jalarie
09-03-2003, 12:15 PM
V=prompt('?',0);
if ((V.match(/^[0-9]*$/))
|| (V.match(/^[0-9]*\.[0-9]{2}$/))
|| (V.match(/^[0-9]*\,[0-9]{3}$/))
|| (V.match(/^[0-9]*\,[0-9]{3}\.[0-9]{2}$/))) {
alert('good');
} else {
alert('bad');
}