My Flash Resource – New Ideas and News for Applying Flash to Complex Gaming Apps

Latest News and Developments

April 17, 2008

AS3 Email and Phone Validation code snippit

by @ 2:47 pm. Filed under AS 3.0 Code Snippits

Email Validation:

function validateEmail(email:String):Boolean {
var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
return ! emailExpression.test(email);
}

Phone Validation:

function validatePhone(phone:String):Boolean {
var emailExpression:RegExp = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/i;
return ! emailExpression.test(phone);
}

Regular Expressions in AS3

by @ 2:46 pm. Filed under AS 3.0 Code Snippits

The following bit of code is used to count the number of times a substring shows up in a string:

// create a String
var str:String = “http://www.storyofstuff.com http://www.myflashresource http://www.adobe.com”;

// create the pattern that your looking for
var pattern:RegExp = /http:\/\/+/g;

// count the number of times the pattern shows up in the string.
var results:Array = str.match(pattern);
trace(results.length); // 3

Actionscript 3.0 makes it easy to do regular expressions. In the past I’ve always used PHP for this just because it was a bit simpler than doing it in Actionscript 2.0.

« Previous Page

My Flash Resource - A continually growing collection of tutorials, thoughts and interests of a Flash Animator and/or Developer.

categories:

other:

New Feedburner Feed!


Feel free to syndicate.

Learning Material

Flash Resources:


Listed on BlogShares
  • Resources