ActionScript RegEx

Regular expressions are very handy when you need to validate user input. JavaScript provides the RegExp object but ActionScript doesn't have a built-in equivelant. So I went on the hunt to see what was out there and stumbled across this site:http://www.jurjans.lv/flash/RegExp.html which offers a home grown class that claims to bealmost 100% compatible with JavaScript 1.2 standard.

For a project I am developing in Macromedia Flex, I needed a website url validator. There are several standard validators (i.e. email, zip code, phone number, etc.) but no URL validator. So I decided to put Pavlis' RegExp class through it's paces.

I discovered that it works "as advertized"! I was able to quickly and easily create the URL validator using a regular expression. Here is the code snippet:

Note: The regular expression I chose to use here is just an example of a URL validation expression. I tend to useĀ http://www.regexlib.com/ as a resource when looking for regular expressions. Also, note the double backslashes where you might expect a single. The ActionScript compiler tries to interpret the character following backslash before the argument is passed to the RegExp constructor. The double slash escapes the backslash.