[thelist] javascript1.2 v mac regexp problem
Andrew Clover
and-evolt at doxdesk.com
Tue Apr 19 05:53:21 CDT 2005
Alex <alex at deltatraffic.co.uk> wrote:
> var regexpress = new RegExp(/^[a-z]+$/i);
/^[a-z]+$/i is the literal syntax for RegExp objects; you don't need to
pass one to the RegExp constructor, it's a RegExp already.
The RegExp constructor takes a string as parameter. If you pass in a
RegExp instead there will be unspecified results; on Mac browsers it
seems to convert the RegExp to the expected type String
('/\/^[a-z]+$\//i', which when recompiled does not result in the pattern
you want).
I personally prefer to construct RegExps from strings rather than using
literal syntax, as it causes fewer syntax-error problems with eg. old
Opera versions and some constructs between IE and Mozilla:
var allLetters= new RegExp('^[a-z]+$', 'i');
(Also then you can dump the language="JavaScript1.2".)
> var testname=regexpress.test(forename);
> var testname2=regexpress.test(surname);
This name checker is rather unforgiving. Should someone be blessed with
the names "Mary Jane O'Foo" or "Marie-Claude von Umläüt" they won't be
able to use the form. A more liberal test like a simple
is-not-blank-string or contains-at-least-one-letter might be less
alienating.
> var forename = document.FrmRegister.forename.value;
document.forms.FrmRegister.elements.forename.value for slightly more
reliability.
--
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/
More information about the thelist
mailing list