www.webdeveloper.com
Results 1 to 2 of 2

Thread: Split numbers from string

  1. #1
    Join Date
    Jan 2003
    Posts
    69

    Split numbers from string

    Hello,

    I have this string:
    field = "due_date31";

    is there a way to split it into two vars so it will be like:
    var 1 = "due_date";
    var 2 = "31";

    many thanks!

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You may use Regular Expressions:
    Code:
    <script type="text/javascript">
    var field = "due_date31";
    var number=field.match(/\d/g).join('');
    var nonnumber=field.match(/[^\d]/g).join('');
    </script>
    More about RegExp:
    http://lawrence.ecorp.net/inet/samples/regexp-intro.php

    And a note:
    Quote Originally Posted by scialom
    var 1 = "due_date";
    var 2 = "31";
    Take care. Variables and function names can not start with a number. The first character should be either a letter or an underscore.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles