Form Validation with RegExp in AS3
November 7, 2007 08:41 am
RegExp is a new native class for ActionScript 3 that lets you work with regular expressions, which are patterns that you can use to perform searches in strings and to replace text in strings. Natively supported by many programming languages, ActionScript 3.0 implements regular expressions as defined in the ECMAScript edition 3 language specification (ECMA-262). Specifically for Flash or Flex development, RegExp will most likely be useful for any data validation or search and replace any string.
For example, you would like to verify a string contains the letters "AS", you would do
The regular expression to see if a string contains the letter "AS" is /AS/ (remember the '/' before and '/' after the expression), and the above function defines a new RegExp Object and test it against a variable called sString.
There are a lot more complicated regular expression syntax, you can start from the Adobe AS3 LiveDocs here to learn more. Here's a class we made to do simple form validation for AS3:

