From 339aae0b8b53f1ad906f71fe8200711e6dcb330b Mon Sep 17 00:00:00 2001 From: Julio Cesar Laura Date: Mon, 24 Sep 2012 01:35:34 -0400 Subject: [PATCH] BUG 5781 Add stripNonNumeric() function to common.js SOLVED - Add new function stripNonNumeric --- gulliver/js/common/core/common.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gulliver/js/common/core/common.js b/gulliver/js/common/core/common.js index 2041b1a0f..d1072b679 100755 --- a/gulliver/js/common/core/common.js +++ b/gulliver/js/common/core/common.js @@ -2132,3 +2132,16 @@ var mb_strlen = function(str) { 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; +}; \ No newline at end of file