# Validation for input box AS2

**URL:** <https://forum.kirupa.com/t/validation-for-input-box-as2/310438>\
**Category:** flash\
**Created:** [June 10, 2010, 5:45am UTC](https://forum.kirupa.com/t/validation-for-input-box-as2/310438 "2010-06-10T05:45:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghozt123](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@ghozt123](https://forum.kirupa.com/u/ghozt123)\
**Post date:** [June 10, 2010, 5:45am UTC](https://forum.kirupa.com/t/validation-for-input-box-as2/310438/1 "2010-06-10T05:45:16Z")

</div>

Hello

I have tried to make validation code for an input box (flash 8) however I cant seem to get it to work, heres the code i have

allow = new Array(" “,“a”,“b”,“c”,“d”,“e”,“f”,“g”,“h”,“i”,“j”,“k”,“l”,“m”,“n”,“o”,“p”,“q”,“r”,“s”,“t”,“u”,“v”,“w”,“x”,“y”,“z”,” ",“A”,“B”,“C”,“D”,“E”,“F”,“G”,“H”,“I”,“J”,“K”,“L”,“M”,“N”,“O”,“P”,“Q”,“R”,“S”,“T”,“U”,“V”,“W”,“X”,“Y”,“Z”);

function validate(user\_name){

```
	for(i=0;i&lt;allow.length;i++){
		if(user_name.indexOf(allow*) != -1){
		temp2++
		}
	}

```

}

// when the user presses the button it runs teh following code  
btn\_continueS3.onPress = function(){

```
	//runs the validation
	validate(user_name)

	if(user_name.length==temp2){
			temp1=0}else{temp2=0
			error_messege=" Please ONLY use letters of the english Alphabet";
			}

			if(temp1==0){
				gotoAndPlay("Scene 2", 1)
			}

```

}

The basic gist is that it runs throught the input box and checks if the letters are in the array, and if they are it adds 1 to temp2

then at the end it checks how many characters are in the input box, and if they equal == temp2 then it goes to the next scene, else it says “Please…etc”

The PROBLEM is that if the user types in a letter twice, such as " HELLO" then the code only counts 1 L instead of 2 L’s. so then it throws out the sum because it wont be correct. ☹

Any ideas?

Thanks  
-ghozt123
