1

I will briefly explain my issue:

I have a numbers looks like this: 971505896321;971505848963;971505478231;971509856987;

My client should write the above numbers in a text field and I should take the 971505896321 and 971505848963 and 971505478231 and 971509856987 and add them into a list.

I success now to add the numbers to the list but I have difficulties how to get the numbers without ;.

function AddPhoneNo()
{   
    var recipientNumber = document.smsmobile.mobile_no;
    var opt = "<option value='" + recipientNumber.value + "'>" + recipientNumber.value + "</option>"

    if  (recipientNumber.value != "")
    {
        if(verifyPhone(recipientNumber.value))
        {
             $('#selectedOptions').append(opt);


            recipientNumber.value = "";
        }
    }       
}

All the numbers should start with 971 and the length of each number is 12. For example: 971506987456.

Appreciate your help.

Thanks,

1
  • 1
    use .split(";") function of javascript. e.g; var mobileNumberArray = recipientNumber.split(";"); Commented May 29, 2012 at 11:33

2 Answers 2

2
var recipientNumber = "971505896321;971505848963;971505478231;971509856987;";
var mobileArr = recipientNumber.split(";");

and then u can run a loop on the above array and add those to your options

Sign up to request clarification or add additional context in comments.

Comments

1

You just need to replace ; if I m getting you corretly than code for you is

var recipientNumber = document.smsmobile.mobile_no.replace(';',''); 

EDIT

if you are entering all number one than you need to split out your string

var recipientNumber = "971505896321;971505848963;971505478231;971509856987;";
var arrayofNumbers= recipientNumber.split(";"); 
var i; for (i = 0; i < arrayofNumbers.length; ++i)
{ 
   var opt = "<option value='" + arrayofNumbers[i]+ "'>" + arrayofNumbers[i]+ "</option>"

    if  (arrayofNumbers[i] != "")
    {
        if(verifyPhone(arrayofNumbers[i]))
        {
             $('#selectedOptions').append(opt);

        }
    } 
} 

1 Comment

Thank you for your answer, but this will add all the numbers without ';', I need to add each '12' digits as an item in the list

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.