[thelist] [JS] regex function vs. plain function

Joshua Olson joshua at waetech.com
Mon Apr 12 10:05:33 CDT 2004


Thank you for underscoring that important argument against using the numeric
conversion functions for form validation.  Depending on the server-side
scripting language, you are correct in that the lacsidasical handling of
extraneous characters may cause an issue.  Thankfully, some server-side
languages, such as CF, match the conversion almost perfectly (parseInt in JS
and Val in CD) so it becomes less of an issue if a convertible, yet
technically invalid, value is passed.


You made one statement that I don't think is entirely accurate:

"Regex is so much more powerful, you would think that even if
it grabs a bit more of processing time, it saves by doing so much

My problem with this statement is purely a technicality (and I'm running on
far too little sleep) but it stems from the "regex is so much more powerful
[than plain code]" portion of that statement.  I would suggest that regex is
LESS powerful than plain code because ultimately you are constrained to the
matches that you can generate with regex.  Using non-regex code, you could
conceivable perform any number of analytical and complex routines against
the value to make a decision on it.

However, if you are looking for a "bang-for-the-buck" comparison, then you
may be right.  Regex is the way to go for *most* pattern matching scenarios
that you'll encounter on a web form.  A good pattern matching that is
outside of regex's reach is decent spam filtering based on heuristic
patterns, etc.

Nap time.  :-)

Joshua Olson
Web Application Engineer
WAE Tech Inc.

More information about the thelist mailing list