In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters.
A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
Are used to analyze texts and strings and check if they comply with certain parameters.
For example, you can use to validate the input of an e-mail in a form.
Class Actionscript 3.0 allows you to use regular expressions with Flash CS3, Flash CS4, Flex 3 and Flex 4.
I created a very useful list of regular expressions for people like me develop with Adobe Flash.
The following list has been tested with Actionscript 3.0 and Flash CS4.
VALIDATE AN URL
var validURLRegExp:RegExp = /^http(s)?:\/\/((\d+\.\d+\.\d+\.\d+)|(([\w-]+\.)+([a-z,A-Z][\w-]*)))(:[1-9][0-9]*)?(\/([\w-.\/:%+@&=]+[\w- .\/?:%+@&=]*)?)?(#(.*))?$/i;
trace( validURLRegExp.test( "http://www.google.com" ) );
VALIDATE EMAIL ADDRESSES
var validEmailRegExp:RegExp = /^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$/;
trace( validEmailRegExp.test( "flepstudio@gmail.com" ) );
VALIDATE PHONE NUMBERS
it must start with + sign and the international code
var validPhoneNumberRegExp:RegExp = /(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)/;
trace( validPhoneNumberRegExp.test( "+393349713568" ) );
VALIDATE DATE FORMATS
formats DD/MM/YY or DD/MM/YYYY or MM/DD/YY or MM/DD/YYYY
var validDateRegExp:RegExp= /^(\d{1,2})\/(\d{1,2})\/(\d{2}|(19|20)\d{2})$/;
trace(validDateRegExp.test("12/05/1972"));
VALIDATE ALPHANUMERIC CHARACTERS
var validAlphaNumericRegExp:RegExp= /^[a-zA-Z0-9]*$/;
trace(validAlphaNumericRegExp.test("Flep1972"));
VALIDATE UK POSTAL CODES
var validUKpostalCodeRegExp:RegExp= /^([A-Z]{1,2}[0-9][A-Z0-9]? [0-9][ABD-HJLNP-UW-Z]{2})*$/;
trace(validUKpostalCodeRegExp.test("ME7 9AA"));
VALIDATE AUSTRALIAN POSTAL CODES
var validAUpostalCodeRegExp:RegExp= /^((0[289][0-9]{2})|([1345689][0-9]{3})|(2[0-8][0-9]{2})|(290[0-9])|(291[0-4])|(7[0-4][0-9]{2})|(7[8-9][0-9]{2}))*$/;
trace(validAUpostalCodeRegExp.test("2620"));
VALIDATE CANADIAN POSTAL CODES
var validCanadianPostalCodeRegExp:RegExp= /^([ABCEGHJKLMNPRSTVXY][0-9][A-Z] [0-9][A-Z][0-9])*$/;
trace(validCanadianPostalCodeRegExp.test("K1A 0B1"));
VALIDATE DIGITS (WHOLE NUMBERS)
var validDigitsRegExp:RegExp= /^[0-9]*$/;
trace(validDigitsRegExp.test("29647362"));
VALIDATE IP ADDRESSES
var validIPRegExp:RegExp= /^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$/;
trace(validIPRegExp.test("192.168.0.0"));
VALIDATE LOWER CASE ALPHABETIC CHARACTERS
var validLowerCaseRegExp:RegExp= /^([a-z])*$/;
trace(validLowerCaseRegExp.test("filippolughi"));
VALIDATE UPPER CASE ALPHABETIC CHARACTERS
var validUpperCaseRegExp:RegExp= /^([A-Z])*$/;
trace(validUpperCaseRegExp.test("FLEPSTUDIO"));
VALIDATE STRONG PASSWORDS
The password must contain one lowercase letter, one uppercase letter, one number, and be at least 6 characters long.
var validPasswordRegExp:RegExp= /^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$/;
trace(validPasswordRegExp.test("filiPPo1972"));
VALIDATE ZIP CODES
var validZipRegExp:RegExp= /^([0-9]{5}(?:-[0-9]{4})?)*$/;
trace(validZipRegExp.test("40202"));
VALIDATE MAJOR CREDIT CARDS
var validMajorCreditCardsRegExp:RegExp= /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$/;
trace(validMajorCreditCardsRegExp.test("Type here your credit card number and test it"));
VALIDATE DINERS CLUB CREDIT CARDS
var validDinersRegExp:RegExp= /^(3(?:0[0-5]|[68][0-9])[0-9]{11})*$/;
trace(validDinersRegExp.test("Type here your Dyners Club credit card number and test it"));
VALIDATE MASTERCARD CREDIT CARDS
var validMasterCardRegExp:RegExp= /^(5[1-5][0-9]{14})*$/;
trace(validMasterCardRegExp.test("Type here your MasterCard credit card number and test it"));
VALIDATE VISA CREDIT CARDS
var validVisaCardRegExp:RegExp= /^(4[0-9]{12}(?:[0-9]{3})?)*$/;
trace(validVisaCardRegExp.test("Type here your Visa credit card number and test it"));







{ 3 comments… read them below or add one }
It is the only URL pattern that actually works
Thanks very much!
are you sure ?
Hi,
I tried your password validator expression.
Requires the Uppercase and the length, but lets passwords w/o a number in them through…
Just FYI
Cheers
Alex