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 be almost 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.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Adobe Flex
Posted by cmichael on Monday, August 27, 2007 7:06 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Related posts