On Sep 17, 12:38 am, africanshox <[EMAIL PROTECTED]>
wrote:
> i have a serach box that checks for a product code or product keyword.
>
> I need to find out how i can check if the input submitted on this
> search box is a number, and if it is, remove any white spaces.
If by "search box" you mean an input element, then its value is
returned as a string. Since you really don't care about the numeric
properties of the value, only that it contains just numbers, the
simplest and most efficient method is to use a regular expression.
The following creates a function that returns true if the argument
contains one or more spaces or digits. If any non-digit or non-space
character is found, it returns false.
var checkValue = (function() {
var re = /^(\s|\d)+$/;
return function(x) {
return re.test(x);
}
})();
> The reason is that product codes coming from a feed have a space in
> them and it is much easier if i sue jquery rather than go through a
> collection fo nearly 20,000 codes.
It is probably quite simple to write a function that creates an index
to the codes and a routine to search it. It may not be faster than
the above function but it will likely be much more robust if your
codes ever change their format.
--
Rob