G
Gene Wirchenko
Hello:
I wish to validate data on a frontend. One such validation is
whether the input string is a number. I could parseInt() or
parseFloat(), but 1) I do not want to allow E-notation and 2) one form
of number that I want to check for is a dollar amount.
Is there a function (or more than one) that does this, or do I
have to roll my own?
If I do roll my own, one way to do it would be a regex. Is this
a good idea? What other alternatives are there?
I am looking for a general answer to use. I am not too concerned
with speed (unless a given way is way slower than others). General,
bulletproof methods are nicer than those not.
Assume that the parameter is a string. I do not care what
happens if the parameter is null, undefined, or data of another type.
(Unless I should. If so, why?)
Pointers to Websites, in case this has all been covered before,
are welcome.
Sincerely,
Gene Wirchenko
I wish to validate data on a frontend. One such validation is
whether the input string is a number. I could parseInt() or
parseFloat(), but 1) I do not want to allow E-notation and 2) one form
of number that I want to check for is a dollar amount.
Is there a function (or more than one) that does this, or do I
have to roll my own?
If I do roll my own, one way to do it would be a regex. Is this
a good idea? What other alternatives are there?
I am looking for a general answer to use. I am not too concerned
with speed (unless a given way is way slower than others). General,
bulletproof methods are nicer than those not.
Assume that the parameter is a string. I do not care what
happens if the parameter is null, undefined, or data of another type.
(Unless I should. If so, why?)
Pointers to Websites, in case this has all been covered before,
are welcome.
Sincerely,
Gene Wirchenko