[phplib] oohform regexp - Bug or Documentation problem! From: Jeffery Cann (jccann <email protected>)
Date: 11/04/00

Greetings.

According to the JavaScript reference:
http://developer.netscape.com/docs/manuals/communicator/jsref/corea3.htm#1158210

    When using the constructor function, the normal string escape rules
    (preceding special characters with \ when included in a string) are
    necessary. For example, the following are equivalent:

    re = new RegExp("\\w+")
    re = /\w+/

So, when sending a regexp to the ooh form->addElement() method:

$f->add_element(array("type"=>"text",
        "name"=>"textBox",
        "valid_regex"=>"^\\\w+$",
        "valid_e"=>"Warning: Required field",
        "value"=>"$text"));

You actually need to send three backslashes (\\\w) so the correct code
\\w is generated. If your "valid_regex" has \\w then the code generated
is \w -> THIS DOES NOT WORK and is quite annoying if you are not regexp
user!

IMHO, this is a bug, but the workaround is a good example in the PHPlib
docs that shows that you have to triple escape metacharacters so the OOH
form class will generate working javascript.

--
jccann [at] home [dot] com

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>