lastingforhours
Programmer
i have an input text field where the user will type in an email address and submit some data. when they click submit i want it to check to see if that text field contains the @ symbol and if it doesnt, it will stop and let them know that they need to enter a valid email address.
no matter what i do, it always returns false when there is in fact an @ symbol in the string. can someone help me with this? here are the three functions that i tried...
1) Comparing characters
function validateEmail() {
var str:String = email.text;
var size:Number = str.length;
var temp:Boolean;
//
for (i=0; i<size; i++) {
if (str == "@") {
temp = true;
} else {
temp = false;
}
}
return temp;
}
2) Comparing ASCII Codes
function validateEmail() {
var str:String = email.text;
var size:Number = str.length;
var temp:Boolean;
//
for (i=0; i<size; i++) {
if (str.charCodeAt(i) == 64) {
temp = true;
} else {
temp = false;
}
}
return temp;
}
3) Converting string to array
function validateEmail() {
var str:String = email.text;
var size:Number = str.length;
var strArray:Array = str.split("");
var temp:Boolean;
//
for (i=0; i<size; i++) {
if (strArray == "@") {
temp = true;
} else {
temp = false;
}
}
return temp;
}
thanks!!
no matter what i do, it always returns false when there is in fact an @ symbol in the string. can someone help me with this? here are the three functions that i tried...
1) Comparing characters
function validateEmail() {
var str:String = email.text;
var size:Number = str.length;
var temp:Boolean;
//
for (i=0; i<size; i++) {
if (str == "@") {
temp = true;
} else {
temp = false;
}
}
return temp;
}
2) Comparing ASCII Codes
function validateEmail() {
var str:String = email.text;
var size:Number = str.length;
var temp:Boolean;
//
for (i=0; i<size; i++) {
if (str.charCodeAt(i) == 64) {
temp = true;
} else {
temp = false;
}
}
return temp;
}
3) Converting string to array
function validateEmail() {
var str:String = email.text;
var size:Number = str.length;
var strArray:Array = str.split("");
var temp:Boolean;
//
for (i=0; i<size; i++) {
if (strArray == "@") {
temp = true;
} else {
temp = false;
}
}
return temp;
}
thanks!!