Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking the length of a string item in a list.

Status
Not open for further replies.

jmorris

Programmer
May 2, 2000
15
AU
I have a textarea box in a form. Within that text area box, the user will insert a list of phone numbers seperated by a comma.

I do not want to restrict the total amount of characters inserted into the textarea as we want to keep the actual list limitless.... however, I do want to show an alert if a user types in a phone number longer than 15 characters.

ie: 5557894, 12345678901234567890, 7444954

First Item is ok.
Third Item is ok.
Second Item is longer than 15 characters, therefore show an alert telling the user that this number is too long and they need to shorten it.

We have tried a function which puts the list into an array then loops through the array to check, but just can't get it working.

***THE CODE***
function check_num_length()
{
var num_array=document.my_form.bw_list.value.split(",");

for (int i = 0, i < num_array.length, i++)
{
if (num_array.length > 15)
{
alert(&quot;Number is too long&quot;);
}
}
}
**************

Any suggestions will be greatly appreciated.

Jason Morris.
 
Dear Jason,

Try this...

for (int j=0, j<num_array.length, j++)
{
if (num_array[j].length > 15)
{
alert(&quot;Number is too long&quot;);
}
}
}

Hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top