It's a pretty common occurrence to see a programmer completely disregard regular expressions, instead implementing his own validating code. A handful of the Do-It-Your-Selfers will even implement their own substring searching algorithm with all sorts of varieties of loops and the like. David Conrad's colleague managed to not only skip the built-in parseFloat method, but use regular expressions, an array, and a loop to do so ...
function testNum(strNum) { if (strNum.length == 0) return false; var theChar, idx, isValid; var theRegExp = /[0;1;2;3;4;5;6;7;8;9;.;-]/ var charArray = strNum.split("") for (idx = 0; idx < charArray.length; idx++) { theChar = charArray[idx] isValid = theChar.search(theRegExp) if (isValid == -1) // a character was found that was not numeric { return false; } } return true; }
[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!