PDA

View Full Version : validation form problems!


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;
}

Crismo
02-13-2006, 07:12 AM
Look at your nickname text field, you are accessing its content by way of nickname.text. The same goes if you have a field called errorMsg.

errorMsg.text = the stuff that normally goes in trace.

markusdoc
02-13-2006, 07:44 AM
Ah cool, it looks like its working, thank you!!

The only problem now is that it doesn't delete the message once all the correct info has been entered? And is it easy to put an option that if all is correct gotoAndPlay next frame?

stop();
submit_btn.onRelease = function(){
name_field.text.isEmpty("name",4);
email_field.text.isEmail();
message_field.text.isEmpty("message",10);
}
String.prototype.isEmpty = function(field,min_chars){
var str = this;
if(this == ""){
trace("Please fill in the " + field +" field");
return false;
}
else if(this.length < min_chars){
trace("The "+ field +" you entered is invalid - not enough characters.");
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;
}

Crismo
02-13-2006, 08:14 AM
To clear the text field when everything is ok set it to “” (eks: nickName.Text = "";).
And yes if everything is ok then just say gotoAndPlay(fram name) etc.

markusdoc
02-13-2006, 08:31 AM
it tells me that that kind of quotation mark is not allowed in AS. But I'm not quite sure where I am supposed to place that code actually?