JRS: In article <vgRCc.14444$HS3.10438@edtnps84>, seen in
news:comp.lang.javascript, Axel Foley <de*******@synchkat.com> posted at
Fri, 25 Jun 2004 08:21:47 :
I used some of the excellent resources from DITHERING.COM for help in my
?????????groveling newbie attempts to cough up working form validation....
US codes look like 12345, 123456789, 12345-6789
CA codes look like B2B2B2, B2B 2B2
Consider
function validCode(zip) { var OK // or \s? v
OK = /^(\d{5}|\d{9}|\d{5}-\d{4}|[a-z]\d[a-z]\s*\d[a-z]\d)$/i.test(zip)
return OK }
function validCode(zip) {
var zip = removeSpaces(zip);
...
// Check that a Canadian postal code is valid
if (zip.search) {
zip = removeSpaces(zip);
Did you not already remove them?
IMHO, removing too many spaces is a mistake; for example, Ol 944 5683
has 9 digits, but is much more likely to be an old munged UK phone
number than a new US Zip.
RegExp tested in <URL:http://www.merlyn.demon.co.uk/js-valid.htm#RT>.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for 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.