Results 1 to 4 of 4

Thread: split a string

  1. #1
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default split a string

    I know I can split a string based on one delimiter
    e.g.
    var field=input.value.split("/")[0]
    will split a field input string at every "/"
    I would like to give a user the option of using "/ "or "-" or "." as a delimiter.

    I can't seem to get this to work as easily as in php.

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    try something like this:

    somestring.split(userinput);

    that's basically it.

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,925
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    Code:
    var re=new RegExp('[/\.-]');
    var field=input.value.split(re)[0]
    Or:

    Code:
    var field=input.value.split(/[\/\.-]/)[0]
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Problem solved many thanks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •