Btn Enviar:
Código :
on (release) {
if (checkAddress(email)) {
// Calls function "checkAddress"
gotoAndPlay("ready");
loadVariablesNum("contacto.php", 34, "POST");
showerror("Error al enviar formulario....");
// Return true
} else {
stop();
// Return False
}
}Validacion de los campos:
Código :
stop();
// ******************************************************
//
// This function is called from the buttom "ok"
//
// ******************************************************
//
function checkAddress(email) {
//
var FirstAT = email.indexOf("@");
// placement of the first "@" in "sender_email"
var LastAt = email.lastIndexOf("@");
// placement of the last "@" in "sender_email"
var theLength = email.length;
// Number of characters in "sender_email"
var LastDot = email.lastIndexOf(".");
// placement of the last "." (dot) in "sender_email"
var specialCharacter = " ~!#$%^&*()+|=`[]{};:<>,?/\\\"'\r\n";
// Characters that are not allowed in an emailaddress
//
trace("FirstAT : "+FirstAT);
trace("LastAt : "+LastAt);
trace("theLength : "+theLength);
trace("LastDot : "+LastDot);
//
if (nombre eq "") {
// if sender_name is empty
nombrepro = "(*)";
// error Output
return false;
}
if (direccion eq "") {
// if sender_name is empty
direpro = "(*)";
// error Output
return false;
}
if (codigopostal eq "") {
// if sender_name is empty
codigopro = "(*)";
// error Output
return false;
}
if (telefono eq "") {
// if sender_name is empty
telpro = "(*)";
// error Output
return false;
}
if (asunto eq "") {
// if sender_name is empty
asuntopro = "(*)";
// error Output
return false;
}
if (email eq "") {
// if sender_name is empty
emailpro = "Ingrese Email";
// error Output
return false;
}
//
if (FirstAT != LastAt || FirstAT<1 || FirstAT>(theLength-4)) {
// 1) If "FirstAT" is not equal "LastAt" it tells us that there is more than one "@"
// 2) If "FirstAT" is smaller than 1 (there must be at least on character before the "@")
// 3) If FirstAt is bigger than the length of "sender_email" minus 4. (there will allways
// be at least on dot an 3 characters after the "@")
emailpro = "*Email incorrecto";
// error Output
return false;
}
//
if (LastAT>LastDot) {
// Makes sure that LastDot if placed AFTER last AT (@)
emailpro = "*Email incorrecto";
// error Output
return false;
}
//
if ((theLength-lastDot)<3 || (theLength-lastDot)>5) {
// 1) If the length minus last dot is less than 3 (There must be at least a dot and two characters in the end of an Email)
// 2) If the length minus last dot is more than 5 (There can be no more than 4 characters after the dot in an Email)
emailpro = "Email incorrecto";
// error Output
return false;
}
//
for (i=0; i<specialCharacter.length; i++) {
// loop
if (email.indexOf(specialCharacter.substr(i, 1))>=0) {
// "indexOf" returns the value "-1" if the character is NOT in "sender_mail"
// If the retur of this "for loop" is greater than zero there IS an nonvalid character in "sender_email"
emailpro = "*Email incorrecto";
// error Output
return false;
}
}
//
if (email.length<=5) {
// (An email must contain more than 5 characters incl. @ and . )
emailpro = "*Email incorrecto";
// error Output
return false;
}
if (pregunta eq "") {
// if sender_name is empty
menspro = "(*)";
// error Output
return false;
}
//
//
return true;
}