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

Joshua Olson joshua at waetech.com
Fri Apr 9 19:14:41 CDT 2004


> -----Original Message-----
> From: Tom Dell'Aringa
> Sent: Friday, April 09, 2004 10:29 AM
>
> We're using a function that checks for a valid number entry. It works
> fine but I am wondering if a regex would be more efficient - it
> certainly seems it would be smaller. Here is the function:

> Wouldn't this be better as a regex? We have like 3 or 4 of these...

Tom,

Regex's are pretty expensive, so perhaps not.  But, I'd suggest you look at
performing this same check by using the built-in type casting methods.
Simply trap the error (using try... catch) so that the method doesn't exit
out.  If it errors when you try to convert to float or int, then you know
the value isn't valid.

Best of luck,

<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com/service_areas/
706.210.0168




More information about the thelist mailing list