In this sample there are 2 function 1 is AllowedEmailCharacters and other is trim. Trim function is 2 function 1 is ltrim > Left Trim and 2 is Right Trim
if (AllowedEmailCharacters("ssdf") != true) {
trace("false");
} else{
trace("True");
}
function AllowedEmailCharacters(Characters1:String):Boolean {
Characters = trim(Characters1);
var hexChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_@.-";
// Validate that it contains the expected characters
for (var i = 0; i<Characters.length; i++) {
if (hexChars.indexOf(Characters.charAt(i))<0) {
return false;
}
}
return true;
}
function trim(matter) {
return ltrim(rtrim(matter));
}
function ltrim(matter) {
if ((matter.length>1) (matter.length == 1 && matter.charCodeAt(0)>32 && matter.charCodeAt(0)<255)) {
i = 0;
while (i<matter.length && (matter.charCodeAt(i)<=32 matter.charCodeAt(i)>=255)) {
i++;
}
matter = matter.substring(i);
} else {
matter = "";
}
return matter;
}
function rtrim(matter) {
if ((matter.length>1) (matter.length == 1 && matter.charCodeAt(0)>32 && matter.charCodeAt(0)<255)) {
i = matter.length-1;
while (i>=0 && (matter.charCodeAt(i)<=32 matter.charCodeAt(i)>=255)) {
i--;
}
matter = matter.substring(0, i+1);
} else {
matter = "";
}
return matter;
}

No comments:
Post a Comment