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:
@@ -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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user