[HELP] Problem with match()

Discussion in 'JavaScript' started by Hipto, Aug 11, 2011.

  1. #1
    Hey guys I've 1 question. This code works:
    if(document.form.filed.value.match( /Your text/ig))

    but if I want to add << http://www >> e.g
    if(document.form.filed.value.match( / http://www /ig))

    it doesn't work :( is it because of the 'slash'?
     
    Solved! View solution.
    Hipto, Aug 11, 2011 IP
  2. #2
    you need to escape the slashes..
    if(document.form.filed.value.match( / [url]http:\/\/www[\/url] /ig))
    Code (markup):
    if it still doesn't work, escape the regular expression symbols that should be text..
    if(document.form.filed.value.match( / [url]http:\/\/www[\/url] /ig))
    Code (markup):
     
    JohnnySchultz, Aug 12, 2011 IP
  3. Hipto

    Hipto Peon

    Messages:
    939
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks JohnnySchultz! :)
     
    Hipto, Aug 12, 2011 IP
  4. Hipto

    Hipto Peon

    Messages:
    939
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi I've one more questions, how to add 'wildcard', for example will this works

    if(document.form.filed.value.match( / http:\/\/*.com /ig))
     
    Hipto, Aug 12, 2011 IP
  5. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #5
    yes it will, but it will also valid for invalid url forms..

    http://i-@m-an-!nvALiD_d0maiN.com

    you may want to just use this..

    if(document.form.filed.value.match( / http:\/\/[a-z0-9\-\_\.].com /ig))
     
    JohnnySchultz, Sep 19, 2011 IP