JRS: In article <ff**************************@posting.google.com >, seen
in news:comp.lang.javascript, David W. Burhans
<da*************@yahoo.com> posted at Tue, 16 Sep 2003 10:31:58 :-
function checkpostcode(form)
{
var min = 4;
var numberFormat = /^\d{4}$/;
if (form.postcode.value.length == min)
{
if (numberFormat.test(form.postcode.value)
There is no need to pre-test the length explicitly when the RegExp does
it perfectly well.
If the value entered was generally the wrong length, it is possible that
insignificant execution time might be saved by the pre-test, at a cost
of increased download time.
If doing the pre-test, the RegExp test should be /\D/ since any non-
digit is immediately fatal; this certainly saves insignificant time.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.