Adding OL.String.isNumeric method to test for numeric strings. r=crschmidt (closes #1441)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7451 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-06-25 20:37:29 +00:00
parent 351b3b756b
commit 8773d98834
2 changed files with 62 additions and 0 deletions

View File

@@ -134,6 +134,31 @@ OpenLayers.String = {
}
}
return tokens.join("");
},
/**
* Property: OpenLayers.String.numberRegEx
* Used to test strings as numbers.
*/
numberRegEx: /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/,
/**
* APIFunction: OpenLayers.String.isNumeric
* Determine whether a string contains only a numeric value.
*
* Examples:
* (code)
* OpenLayers.String.isNumeric("6.02e23") // true
* OpenLayers.String.isNumeric("12 dozen") // false
* OpenLayers.String.isNumeric("4") // true
* OpenLayers.String.isNumeric(" 4 ") // false
* (end)
*
* Returns:
* {Boolean} String contains only a number.
*/
isNumeric: function(value) {
return OpenLayers.String.numberRegEx.test(value);
}
};