Okay so far I have not been very consistent on this blogging thing. I have been really busy lately. I plan on posting more often. I have been working a lot in Flex (Flash Builder 4 Beta). The other day I was building a form and took a look at the EmailValidator class in the Flex Framework. The class is pretty sweet and appears to be pretty robust. Sometimes that is exactly what you want, however sometimes you just want a super simple, easy-to-use email validation method. Because of that need I wrote a really simple email validation class. It is really simple and basically just checks for an ‘@’ symbol and a ‘.’ character, but it is really easy to implement. It’s not like the other email validators actually validate the email anyway. They may be more complex, but it’s not like they actual validate it by sending an email. So anyway I have included the source code to this class and if you are looking for an easy way to validate an email feel free to use it and adapt it as your heart desires. It is written in ActionScript 3.0, but it would be really easy to convert it to AS 2.0 if for some reason you were programing in that. Here is what the code looks like:
package { public class EmailValidator { public static function validateEmail(emailAddress:String):Boolean { var testsPassed:uint = 0; if(emailAddress.indexOf('@') > 0) testsPassed++; if(emailAddress.lastIndexOf('.') > emailAddress.indexOf('@')) testsPassed++; if(testsPassed == 2) return true; else return false; } } }
Here is a link to the source files: Email Validator The .fla file was saved in Flash CS4 so to open it you would need that version or later. Continue reading “Email Validator for Flash”