www.webdeveloper.com
Results 1 to 2 of 2

Thread: I want to match " @"+ any character javascript/jquerr

  1. #1
    Join Date
    Aug 2010
    Posts
    6

    I want to match " @"+ any character javascript/jquerr

    Hi,

    This is what I want to match inside of a textarea:

    " @"+any character to perform an autocomplete operation to find for users when the @ is called and a character is added next to it as the term.

    this is the textarea

    Code:
    <textarea></textarea>
    this is the js:
    Code:
    function strpos (haystack, needle, offset) {
       var i = (haystack + "").indexOf(needle, (offset || 0));
        return i === -1 ? false : i;
    }
    
    var dauto=function(){
    if(strpos($(this).val(),"@ "+reg_exhere)!==false){
    alert("match found");
    }
    }
    
    $("textarea").bind("keyup",dauto);
    $("textarea").bind("keydown",dauto);
    Now I really don't know what to use as the regular expression in there, plus I don't know if using it in there would help as it would loose the look up for the @ before any character so the following string would return true:

    " @ mystring"

    as whereas I only need to find:

    " @anycharacterhere"

    Thanks so much.

  2. #2
    Join Date
    Jun 2008
    Posts
    106
    Code:
    var val = $(this).val();
    var regex = /@\s*\w+/;
    
    if ( regex.test(val) ) {
        // true, do something
    }

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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