diff options
author | Andrew Dolgov <[email protected]> | 2005-10-17 04:24:40 +0100 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2005-10-17 04:24:40 +0100 |
commit | b6644d296a9e29a39e052a84324ccc806787a401 (patch) | |
tree | 61d2a57cb43d0ddcbbf89456c207c0a0cbc04d17 /functions.js | |
parent | 52b51244c167816c83ebee45e746433c881a3a8b (diff) |
add isNumeric() to functions
Diffstat (limited to 'functions.js')
-rw-r--r-- | functions.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/functions.js b/functions.js index 77be7d407..baee89558 100644 --- a/functions.js +++ b/functions.js @@ -362,3 +362,37 @@ function popupHelp(tid) { "Popup Help", "menubar=no,location=no,resizable=yes,scrollbars=yes,status=no"); } + +/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj + * * @author Sundar Dorai-Raj + * * Email: [email protected] + * * This program is free software; you can redistribute it and/or + * * modify it under the terms of the GNU General Public License + * * as published by the Free Software Foundation; either version 2 + * * of the License, or (at your option) any later version, + * * provided that any use properly credits the author. + * * This program is distributed in the hope that it will be useful, + * * but WITHOUT ANY WARRANTY; without even the implied warranty of + * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * * GNU General Public License for more details at http://www.gnu.org * * */ + + var numbers=".0123456789"; + function isNumeric(x) { + // is x a String or a character? + if(x.length>1) { + // remove negative sign + x=Math.abs(x)+""; + for(j=0;j<x.length;j++) { + // call isNumeric recursively for each character + number=isNumeric(x.substring(j,j+1)); + if(!number) return number; + } + return number; + } + else { + // if x is number return true + if(numbers.indexOf(x)>=0) return true; + return false; + } + } + |