markusdoc
02-13-2006, 06:57 AM
Hi there,
I am tyring to place a validation form in to my movie using the tutorial below, but seen as it is using the "trace" function the errors only appear in the output box, how can I get it to appear in a text field instead???
stop();
submit_btn.onRelease = function(){
nickname.text.isEmpty("name",4);
email_field.text.isEmail();
}
String.prototype.isEmpty = function(field,min_chars){
var str = this;
if(this == ""){
trace("Please fill in the " + field +" field");
return false;
}
return true;
}
String.prototype.isEmail = function(){
var invalid_message = "Invalid email address";
var str = this;
var req_chars = new Array("@",".");
var bad_chars = new Array();
if(!(this.isEmpty("email",6))){
return false;
}
for(i=0;i<200;i++){
if((i>=33 && i<=45) || i == 47 || (i>=58 && i<=63) || (i>91 && i<=96)
|| (i>=123 && i<=126) || (i>=161 && i<=199)){
var char = String.fromCharCode(i);
bad_chars.push(char);
}
}
for(i=0;i<bad_chars.length;i++){
if(str.indexOf(bad_chars[i]) != -1){
var char = bad_chars[i];
trace(invalid_message);
return false;
}
}
for(i=0;i<req_chars.length;i++){
if(str.indexOf(req_chars[i]) != -1){
index = str.indexOf(req_chars[i]);
if(str.indexOf(req_chars[i],(index+1)) != -1 && req_chars[i] != "."){
trace(invalid_message);
return false;
}
}
else{
trace(invalid_message);
return false;
}
}
return true;
}
I am tyring to place a validation form in to my movie using the tutorial below, but seen as it is using the "trace" function the errors only appear in the output box, how can I get it to appear in a text field instead???
stop();
submit_btn.onRelease = function(){
nickname.text.isEmpty("name",4);
email_field.text.isEmail();
}
String.prototype.isEmpty = function(field,min_chars){
var str = this;
if(this == ""){
trace("Please fill in the " + field +" field");
return false;
}
return true;
}
String.prototype.isEmail = function(){
var invalid_message = "Invalid email address";
var str = this;
var req_chars = new Array("@",".");
var bad_chars = new Array();
if(!(this.isEmpty("email",6))){
return false;
}
for(i=0;i<200;i++){
if((i>=33 && i<=45) || i == 47 || (i>=58 && i<=63) || (i>91 && i<=96)
|| (i>=123 && i<=126) || (i>=161 && i<=199)){
var char = String.fromCharCode(i);
bad_chars.push(char);
}
}
for(i=0;i<bad_chars.length;i++){
if(str.indexOf(bad_chars[i]) != -1){
var char = bad_chars[i];
trace(invalid_message);
return false;
}
}
for(i=0;i<req_chars.length;i++){
if(str.indexOf(req_chars[i]) != -1){
index = str.indexOf(req_chars[i]);
if(str.indexOf(req_chars[i],(index+1)) != -1 && req_chars[i] != "."){
trace(invalid_message);
return false;
}
}
else{
trace(invalid_message);
return false;
}
}
return true;
}