JRS: In article <cg********@odak26.prod.google.com>, dated Thu, 26 Aug
2004 22:24:08, seen in news:comp.lang.javascript, learner
<v_********@yahoo.com> posted :
I want to validate whether a string is having only alphabets,
numbers, '-' and '_'.
Is there any way to do this like the one in Perl
( /^[0-9][A-Z][_][-]$/) ?
Let me know the earliest?
^ --- please.
That expression does not do what you want, as has been explained.
Rather than testing whether the whole string contains only those
characters with /^[ characters ]*$/ it may be quicker to see if it
contains any character other than those : /[^ characters ]/ .
The latter process should stop at the first alien; the former, depending
on implementation, probably scans the whole string even if it is faulty.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<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.