Validating TExtFields...Agian :(

Sorry to keep reposting this but I am getting frustrated. Here’s my deal. I need to validate 3 text fields: em, nm, ms

now i need to validate these fields and only if they are validated goto frame 10. could someone help?

-thanks
Digital

ok. i would set it up so that you have a dynamic text feild and name it “error” and we will use that in case a feild is not filled in. then use this code… or a variant of it.

[AS]
if (!em.length) {
error = “Please enter blah blah”;
}
else if (!nm.length) {
error = “Please enter blah blah”;
} else if (!ms.length) {
error = “Please enter blah blah”;
}

else {
	goToAndPlay(10);

}
[/AS]

that jsut says, that if the feild is blank, write the error message in the error text box. of couse you could always make it do somthing else like make a popup or go to a different frame or whatever. :slight_smile:

if you need to validate more than blank fields you’ll have to post what you actually want to validate. Ie: zip code (you need to establish some rules) if its a zip code you know it must be 5 chars so you’ll have to evaluate the length to make sure its not greater or less than five. You will also have to validate that if they are numbers and if there are no spaces in it.

so with that said what exactly are you validating? If its a whole form you can see the depth to which your scripts will have to go through. The good thing is that you can create some “default” methods. Ie: ones that check for spaces and ones that check for blank, alpha numeric, numbers only, letters only. However if there is a size requirement you’ll have to check those on their own basis.

now, what are you validating? :slight_smile:

-z

just 3 textfields, nothing crazy. thanks guys!

o btw . coulkd u teell me how the email would be validated. a know (’@’), (’.’)

you can find some good javascript tut’s for validating email address (it would be alsmost identical to AS)

for an email address you need to validate that there are 2 chars before the @ symbol, two characters after the @ and at least 2 characters after the “.” you also need to validate for what you just mentioned.

I have a CD that has this on it somewhere I’ll post the code after i dig it up.

this code is storing all of the error messages in an array called errors. All you need to do is write some code that runs the validate form function (and have all the input fields ready) this is pretty simple if you need some help just write back.

-z

<pre>

function validateForm() {
errorLog.text = “”;
errors.length = 0;
validateEmail();
if (errors.length > 0) {
errorLog.htmlText = "These errors were found:
";
var i = -1;
while (++i < errors.length) {
errorLog.htmlText += errors* + newline;
}
} else {
email = email.text;
gotoAndStop (“Confirm”);
}
}

function validateEmail()
{
if (email.text.indexOf("@") < 2)
{
errors.push("@ missing in email or in the wrong place.");
}
if (email.text.lastIndexOf(".") <= (email.text.indexOf("@") + 2))
{
errors.push(". missing in email or in the wrong place.");
}
if (email.text.length < 8)
{
errors.push(“Email address not long enough.”);
}

</code>