# Determining if data is a number or word combination

**URL:** <https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956>\
**Category:** flash\
**Created:** [August 4, 2002, 4:42pm UTC](https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956 "2002-08-04T16:42:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [August 4, 2002, 4:42pm UTC](https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956/1 "2002-08-04T16:42:22Z")

</div>

Hello everyone,  
I have a simple question. I am running an if statement to determing whether the data entered by a user is a number or a combination of letters and/or numbers. How could I determine whether the data is just numbers? Like:

```php

if (textbox == notanumber) {
    do something
}

```

I have tried using NaN and “undefined” without much success.

Thanks,  
Kirupa :rambo:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 4, 2002, 4:58pm UTC](https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956/2 "2002-08-04T16:58:12Z")

</div>

Do you have to determine it with an IF statement? if so this is probably useless!

I think all characters (at least most) relate to a keycode (possibly ASCII) number for example

A=65, B=66

numbers do also

0=48, 1=49 etc.

you could put the enterred data into an Array, 1 character per array element then test each element.  
If each element’s key code is between 48 and 57 then the data eneterred is all numbers. Once you have determined what the enterred data consists of you could then use your if statement, to do whatever.

I have never used NaN statements, but I would guess for an IF statement that you would use NaN in someway.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 4, 2002, 6:14pm UTC](https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956/3 "2002-08-04T18:14:58Z")

</div>

You could try to find a letter in your text, starting from a to z, and if you find one, then, well, do whatever you want to do.

I believe you’ll need the indexof function. I’ll try and come up with something.

pom :asian:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 4, 2002, 6:59pm UTC](https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956/4 "2002-08-04T18:59:09Z")

</div>

There you go:

```auto
myLetters="abcdefghijklmnopqrstuvwxyz";
myText="1re3";
myBool=false;
for (i=0;i < myLetters.length;i++){
	value=myText.indexOf(myLetters.charAt(i));
	if (value!=-1){
                     myBool=true;
                     break;
               }
}
if (myBool) trace ("There are letters in that text");
else trace ("No letters");

```

myLetters is a string containing all the letters of the alphabet.  
myText is the text you’re testing.  
myBool is false to start with, and remains false if there are no letters.

We browse through the letters of the alphabet to check if one of them is in the string. myLetters.charAt(i) returns each letter from the alphabet independently, and myText.indexOf checks if that letter is in myText.

If it is not, it returns -1, otherwise it returns the index of the letter. So if the index is not -1, FLash has found the letter, hence there is a letter in the string.

Tadaaa!

pom :asian:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 4, 2002, 8:07pm UTC](https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956/5 "2002-08-04T20:07:53Z")

</div>

Hey guys!

I think you’re looking for this:

if(isNaN(textbox)){

if textbox is not a number, it will return a value of True, therefore executing your code in the IF statement.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 4, 2002, 10:56pm UTC](https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956/6 "2002-08-04T22:56:45Z")

</div>

Hey iammontoya,  
That was it! That line of code solved my problem. Thanks a bunch RageW0lf and Iammontya. Thanks to you as well Pom, I am sure that must have taken some effort to do all that.

Cheers!  
Kirupa :bandit:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 5, 2002, 2:21am UTC](https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956/7 "2002-08-05T02:21:39Z")

</div>

no problem, man! That’s why we’re here, to help each other out! Hey, Kirupa… I have a new tutorial ready for you, if you’d like it. Where to send again?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 5, 2002, 6:43am UTC](https://forum.kirupa.com/t/determining-if-data-is-a-number-or-word-combination/956/8 "2002-08-05T06:43:13Z")

</div>

😛 Don’t worry Kirupa, it was fun! And Inigo, nice trick!

pom :asian:
