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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split Command

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
Guys,

I know this is a bit of a simple question to ost but i don't have any JS reference material on hand and I can't locate this on the web.

Can someone please give me an example of the split command. Actually maybe there's a better way of doind what I want to do. i will have a text field and when it displays it will have a $ in it. When the form is submitted, I want to verify that the user has entered a number. So I was going to use split ot get rid of the $ and then verify that the array element was a number.

Any other suggestions are welcome. Mise Le Meas,

Mighty :)
 
Syntax
--split(separator, limit)
Parameters
--separator (Optional) Specifies the character to use for separating the string. The separator is treated as a string. If separator is omitted, the array returned contains one element consisting of the entire string.

--limit (Optional) Integer specifying a limit on the number of splits to be found.

example:

function splitString (stringToSplit,separator) {
arrayOfStrings = stringToSplit.split(separator)
document.write ('<P>The original string is: &quot;' + stringToSplit + '&quot;')
document.write ('<BR>The separator is: &quot;' + separator + '&quot;')
document.write (&quot;<BR>The array has &quot; + arrayOfStrings.length + &quot; elements: &quot;)
}

here's the best online reference I've found for javascript (and where I cut and pasted this from)

 
then you can ask if isNan(number) -- but you probably knew that...

good luck! :)
Paul Prewett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top