Isnumeric ftn in Javascript

Results 1 to 2 of 2

Thread: Isnumeric ftn in Javascript

  1. #1
    Fion Guest

    Default Isnumeric ftn in Javascript

    Is there a similar isNumeric function as in vbScript in Javascript?<BR><BR>Pls advise.<BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default RE: Isnumeric ftn in Javascript

    Not exactly - but you can do this:<BR><BR>var x = 10;<BR>if (x.constructor == Number) { //true<BR>...<BR>}<BR><BR>however, this won&#039t tell you if x is a string that can be evaluated as a number (eg x="10").<BR><BR>You can test to see if a string consists entirely of numberic characters using a regular expression:<BR><BR>if ( == -1) {<BR>... // x consists entirely of numeric characters<BR>}<BR><BR>So you could write an IsNumeric function something like this:<BR><BR>function IsNumeric(varTest) {<BR>**if (varTest.constructor == Number) {<BR>****return true;<BR>**} else if (varTest.constructor == String && == -1) {<BR>****return true;<BR>**} else return false;<BR>}<BR><BR>HTH<BR><BR>Dunc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts