How do I use JavaScript regex to validate numbers like this?
I have tried (used string match Should not be):
test ('2342342342sdfsdfsdf'); Function test (t) {warning (/ \ d {1,3} (, \ d {3}) * (\. \ D \ d)? | \. \ D \ d / .test (t)); } But still gives me the truth.
I am not sure what you mean by valid but it can work.
// console.log is used in firebug. Var isNumber = function (str) {return! IsNaN (str.toString (). Replace (/[.///, '')); } Console.log (isNumber ('1,000.00') === true); Console.log (isNumber ('10000') === true); Console.log (isNumber ('1, ooo.00') === incorrect); Console.log (isNumber ('ten') === incorrect); Console.log (isNumber ('2342342342sdfsdfsdf') === incorrect);
Comments
Post a Comment