SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A question about regular expressions

    Hi,

    I have a variable string and I would like to check whether it contains the following or not:

    "digit"+"digit"+":"

    For example: "02:", "45:", "13:", "88:" etc.

    I tried the following but it didn't work:

    HTML Code:
    myString.indexOf(/[0-9]{2}$/+':')
    Thanks for any ideas.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,340
    Mentioned
    179 Post(s)
    Tagged
    9 Thread(s)
    Hi,

    \d will match any digit and the colon is just a normal character, so you could write:

    Code JavaScript:
    var str="This is my string 99:99"; 
    if (str.match(/\d\d:/)){
      alert("Match found");
    }

    HTH

  3. #3
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Hi,

    \d will match any digit and the colon is just a normal character, so you could write:

    Code JavaScript:
    var str="This is my string 99:99"; 
    if (str.match(/\d\d:/)){
      alert("Match found");
    }

    HTH
    Thanks a lot, it worked.


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
  •