Flash video tutorials

Free Utilities

Events Scroller | Images Scroller | Multi FLV Player | Flash CS3 GuestBook | News Scroller | Tortillas - creator of simple graphs for statistical data | 3D images visualization free utility | Flash CS3 Uploader - free utility | Mini Gallery | Flash CS3 puzzle | Hit counter Flash CS3 + XML + PHP | Multi Audio Player | Newsletter module | Bluring Slide | Monthly Calendar | ShoutBox | StripGallery - Flash CS3 and XML gallery | Email Form PRO | MaskMenu | Elastic Gallery | PhotoNavigator | Pixellation - SlideShow | Email form | Analogue clock | FullScreen images gallery | Rotating header | Flash Portfolio | Polls System | Products Exhibitor | Mini Navigator | Drag Menu | Horizontal Menu | Quizzer | Mini Navigator 2 | Reflect Gallery | Events Scroller - version 2 | Rotating header 2 | Magnifying Glass | Zoomify | MenuVibration | Email form Flash CS3 and ColdFusion 8 | News Scroller 2 | Simple GuestBook | Captcha for Flash CS3 | Email form with pictures - Flash CS3 and PHP | FlepCharCode | Mac Menu | Header | Memory Game - Flash CS3 game | Flash CS3 CountDown | FLV Slide Show Videos | Illusion - images gallery | Tell A Friend | terms of use | Flash RSS reader | ToolTip Flash CS3 - CS4 | Sliding Email Form | ComboMenuHeader | ComboMenuHeader PRO | Mac Front Row in Flash CS3 | FlaTwit - Flash and Twitter - twit this | Store Locator | Multi Video Player MAC style | hittest and magnifying glass | Flash XML editor | BlurSlideShow | ImagesViewer | Video Gallery | Flash XML editor gallery 1 | 15 numbers game | Tipper vertical scroller with Iphone effect | YouTube Video Player by categories | GuestBook Flash CS4 | tweened menu | Twitter RSS reader | Xmas Flash header | Events Scroller - version 3 | TripleBox | BlackComboBox | Inertial Photo Portfolio | Fullscreen Background | Multi Categories Images Gallery |

Useful list of regular expressions with Actionscript 3.0 and RegExp class

by admin on October 29, 2009 · 3 comments

in Sintax

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"));
Share This Post

Related posts

{ 3 comments… read them below or add one }

1

ClockURL.com 11.03.09 at 10:02 am

It is the only URL pattern that actually works

Thanks very much!

2

admin 11.03.09 at 10:03 am

are you sure ?

3

Alex 03.02.10 at 9:27 am

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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Older post:

Newer post: