In comp.lang.javascript message <b4172bf4-299d-4a38-8d2d-32ed3fd34cc5@q2
6g2000prq.googlegroups.com>, Tue, 25 Nov 2008 12:05:27, "Joe [at]
Please read the newsgroup FAQ more carefully.
It must be the EXACT MATCH, such as the value "8" or "9" but not "89"
or "98"...Each vertical bar resembles an exact match, for a total of 7
matches: 8,9,37,38,39,40,46
Is it *necessary* that you use a RegExp method? Is this coursework, set
to you or as self-tuition?
Otherwise, to select a good solution, one needs to know whether the list
of numbers is unvarying and so can be constructed by the author, or is
variable and constructed by code.
Also, is the test to be done once or many times? If the latter, it
might be worth investing in set-up code to make the testing faster.
Is anything known about the strings to be tested? If either there can
be no leading zero or leading zero can be ignored, then they can be
treated as if they were Numbers.
Is the number of allowed values typically about 7? Can it be much
larger?
If constructed by code, consider
// set-up :
var Arr = []
// here construct each number N in turn & do Arr[N] = true
// test number J :
if (A[J]) DoFoundCase() ; else DoNotFoundCase()
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
--
(c) John Stockton, nr London UK.
[email protected] IE7 FF2 Op9 Sf3
FAQ <URL:
http://www.jibbering.com/faq/index.html>.
<URL:
http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:
http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.