Yeah, you're right, that one is a little too simple.

Another one I've used is this:
--------------------------------------------------
// vars
var checkStr:String = "._-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var isValid:Boolean;
var inputTxt:TextInput;
var valBtn:Button;
var resultTxt:TextArea;

function clicked() {
resultTxt.text = (validateEmail(inputTxt.text)) ? "email is valid" : "email is not valid";
}
valBtn.addEventListener("click", clicked);

function validateEmail(ti:String):Boolean {
        // ti = text input field string
        atChrIndex = ti.indexOf("@");
        dtChrIndex = ti.lastIndexOf(".");
        if(atChrIndex < dtChrIndex){
                frstStr = ti.slice(0,atChrIndex);
                mdleStr = ti.slice(atChrIndex+1, dtChrIndex);
                lastStr = ti.slice(dtChrIndex+1, ti.length);
                if(getStrValid(frstStr) && getStrValid(mdleStr) && 
getStrValid(lastStr)){
                        return true;
                } else {
                        return false;
                }
        } else {
                return false;
        }
}

function getStrValid(ti:String):Boolean {
        isValid = true;
        for(var i=0;i<ti.length;i++){
                if(checkStr.indexOf(ti.charAt(i)) == -1) isValid = false;
        }
        return isValid;
}
--------------------------------------------------

The above script check for a "@" followed by the last instance of ".", and then splits the email string into three separate strings, and then checks if all the characters in those strings correspond to checkStr. In my script, more than one "." character is allowed in the email, cause I've seen some addresses being something like "[EMAIL PROTECTED]", which isn't allowed in Bokelberg's script.

Email validation is fine, to a certain point. Maybe it's just me, but I try and spend the least amount of time on the issue; if a user wants to purposefully try and break the email validation (which they would need to in order to get past a script like the above) then they deserve not to get signed up for whatever. A good signup routine is not just about email validation, but about confirmation: if they purposefully put in an invalid email (which gets past the above routine), then they can't confirm. Sucks to be them.

Of course, the simplest thing if you're doing a lot of string validation in your AS2 application is to use a RegExp class.

__________________________________________________________

Joseph Balderson, Flash Platform Developer
http://www.joeflash.ca | 416-768-0987
Writing partner, Community MX | http://www.communitymx.com
Consultant, New Toronto Group | http://www.newyyz.com

Rákos Attila wrote:
Well, this is too simple, there are too many invalid strings which are
considered as valid by this script. I think if you validate the input,
then do it correctly or don't validate at all :) An incomplete
validation makes you feel that your data is valid and secure, however
it can lead to unexpected problems later.

  Attila

JB> I got a much simpler one:
JB> JB> Check for invalidity: JB> JB> // ti = text input field JB> if((ti.text.indexOf("@") == -1) || JB> (ti.text.indexOf(".",(ti.text.indexOf("@")+2)) == -1) ) {
JB>     // email is invalid
JB> }
JB> JB> OR... JB> JB> Check for validity: JB> JB> // ti = text input field JB> if((ti.text.indexOf("@") != -1) && JB> (ti.text.indexOf(".",(ti.text.indexOf("@")+2)) != -1) ) {
JB>     // email is valid
JB> }


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to