SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2011
    Location
    Canada,Montréal
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Regex Find [ and other unusual character JavaScript

    Hi im trying to make a regex to find any of these character: +_)(*&?%$#@!\+¬][}{¤|<>?/"

    but i cant seem to get it to match some characthers. Plz help

    i cant use /W because it will exclude characters like - or é

    here is a exemple of my test

    var str=" Is this % all there is ? > }[ " ;
    var patt1=/[ +_)(*&?%$#@!\+¬][}{¤|<>?/"]/g;
    document.write(str.match(patt1));

    output : ?, >

    it should also have found }[ % ... cant seem to figure why

    plz help , its probably something basic i guess but i cant find it lol.

    Thank you .

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Try escaping them by adding a \ in front of each one that isn't recognised - most of those characters have special meanings in regular expressions and so need to be escaped in order to get back their normal meaning.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2011
    Location
    Canada,Montréal
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var str="{}\\()<>\]\[\/?#!$@\"+_*°|¤";
    var patt1=/[{}\\()<>\]\[\/?#!$@"+_*°|¤]/g;
    document.write(str.match(patt1));

    this one is worcking THX.
    I changed the order of the symbols and it worked and added \ for [,],\,/

    Now in can use this for a input filter to see if the user is trying to input illegal character.
    I had this idea to check for invalid character instead to look for good character.
    I call it revese validation XD.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Sounds like you have an awful lot of valid characters then if only that small fraction of 0.000001% of the possible characters are the only ones that are invalid - take a look at http://en.wikipedia.org/wiki/List_of_Unicode_characters for a partial list of all the characters you are allowing by only blocking those few.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2011
    Location
    Canada,Montréal
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im aware of that but its ok for what i want.


Tags for this Thread

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
  •