BUG 5781 Add stripNonNumeric() function to common.js SOLVED

- Add new function stripNonNumeric
This commit is contained in:
Julio Cesar Laura
2012-09-24 01:35:34 -04:00
parent 58a59822d4
commit 339aae0b8b

View File

@@ -2132,3 +2132,16 @@ var mb_strlen = function(str) {
return len; return len;
}; };
var stripNonNumeric = function (str) {
str += ''; //force str to be a string
var rgx = /^\d|\.|-$/;
var out = '';
for (var i = 0; i < str.length; i++) {
if (rgx.test(str.charAt(i))) {
if (!((str.charAt(i) == '.' && out.indexOf('.') != -1) || (str.charAt(i) == '-' && out.length != 0 ))) {
out += str.charAt(i);
}
}
}
return out;
};