Regular Expressions
Posted in Actionscript, Flash, General on January 30th, 2009 by Sandro Haag – 2 CommentsRegular Expressions is one of the great things that Adobe has done in Actionscript 3. It simplifies the way that you do the validation of email, birthdate, cep…
Almost all programming languages have Regular Expressions, the only thing that modify, is the usage.
Here are some examples:
var regExp:RegExp = /^[a-z][w.-]+@w[w.-]+.[w.-]*[a-z][a-z]$/i;
var isValid:Boolean = regExp.test(”hahahaag@gmail.com”);
trace(isValid); // true
Birthdate
This is one of the longest Regular Expression that I’ve used. It validates the birthdate perfect, including leap year.
var regExp:RegExp = /^(((0[1-9]|[12][0-9]|3[01])([/])(0[13578]|10|12)([/])([1-2][0,9][0-9][0-9]))|(([0][1-9]|[12][0-9]|30)([/])(0[469]|11)([/])([1-2][0,9][0-9][0-9]))|((0[1-9]|1[0-9]|2[0-8])([/])(02)([/])([1-2][0,9][0-9][0-9]))|((29)(.|-|-)(02)([/])([02468][048]00))|((29)([/])(02)([/])([13579][26]00))|((29)([/])(02)([/])([0-9][0-9][0][48]))|((29)([/])(02)([/])([0-9][0-9][2468][048]))|((29)([/])(02)([/])([0-9][0-9][13579][26])))$/i;
var isValid:Boolean = regExp.test(”16/06/1986″);
trace(isValid); // true
You can find many others, searching at Google. The usage is the same.
If somebody finds others interesting RegExp, please send it to me.
Good luck!