JavaScript & DHTML Cookbook
by Danny Goodman
The unconfirmed error reports are from readers. They have not yet been
approved or disproved by the author or editor and represent solely the
opinion of the reader.
Here's a key to the markup:
[page-number]: serious technical mistake
{page-number}: minor technical mistake
: important language/formatting problem
(page-number): language change or minor formatting problem
?page-number?: reader question or request for clarification
This page was updated March 26, 2007.
UNCONFIRMED errors and comments from readers:
[196] Within the body of function isEMailAddr;
The regular expression used in the function is:
var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/
However, this does not correspond to the non-regular expression version of the
function on pp. 194. The above regexpr allows the username part to begin with a
hyphen as it does the domain part, whereas the other version of the function does
not.
Was this intentional? I categorized this as a "serious technical mistake" but perhaps
it just calls for a clarification that the two versions of the function are not
identical in functionality.
Here is my modified version:
var re = /^\w[\w-]*(\.[\w-]+)*@\w[\w-]*\.([\w-]+\.)*[a-zA-Z]{2,}$/;
Here, the username part may not start with a hyphen. Similarly for the domain part. I
believe that it otherwise works identically to the original.
{219} Near the end of the formObj2String(obj) function which starts on page 218;
Any object type that falls throught to the "default:" handler of the
switch(obj.type) statement near the bottom of page 218 will have its attributes
returned with a trailing comma following the type attribute.
eg {name:'someButton',type:'button',}
This will cause the eval function used by string2FormObj(form, str) at the top of
page 220 to choke.
Remedy depends on what the original intention was!
It may also be worth pointing out that I found this error when using the library to
manipulate a form containing a button element.
If I simply fix the existing function to remove the trailing comma
eg:
default:
output = output.substring(0,output.length-1)
then the library will lose the value attribute (if present) of my button.