title: javascript user input validation with regex not working
body: <p>i'm trying to get my regexp and ajax function to work but with no luck.
  i would like to match if the user types "@" character in tinymce and then get it to insert in to jquery post for desired results but the regular expression is not working as it returns null value plus i would like to know if there is a way to validate user input as they type after the spl.char "@" because i can't seem to make the script read after the first user input string (i don't know what to do as i'm scratching my head for hours to make this work) can anyone help me with this and tell me where i'm going wrong.
  the code i tried so far:</p>
  
  <pre><code>function load_Ajax(uname){
      $.post("jsdropdown.php",{"uname":uname},function(res){
          alert(res);
      });
  }
  tinymce.init({
    selector: 'textarea#wall_id_1',
    height: 300,
    theme: 'modern',
    resize: false,
    force_p_newlines: false,
    plugins: 'print preview powerpaste searchreplace autolink directionality advcode visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount tinymcespellchecker a11ychecker imagetools mediaembed  linkchecker contextmenu colorpicker textpattern help',
    toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify  | numlist bullist outdent indent  | removeformat',
    image_advtab: true,
    templates: [
      { title: 'Test template 1', content: 'Test 1' },
      { title: 'Test template 2', content: 'Test 2' }
    ],
    content_css: [
      '//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
      '//www.tinymce.com/css/codepen.min.css'
    ],
  
    init_instance_callback: function(editor) {
          $(editor.contentDocument.activeElement).atwho({at: "@", data: names});
  
    },
        setup: function(editor) {
          editor.on('keyup', function(e) {
  
              var eli= $(editor.contentDocument.activeElement).prop('innerHTML');
  
              var txt=$(eli+'p').html();
            var txt1=$(txt+'br').html();
            var regex=new RegExp(/@+([a-zA-z!._-]+)/g);
             var match= regex.exec(txt1); 
       //console.log(match);
       alert(match);
    load_Ajax(match);
            if(e.keyCode == 13 &amp;&amp; $(editor.contentDocument.activeElement).atwho('isSelecting'))
              return false;
          });
        }
   });
  </code></pre>
  
  <p>update:-
  following @QubaishBhatti advice i changed match var to regex.exec(txt) and the script can read all the user input value perfectly. The new problem is i cant seem to get the ajax response in to an array and pass it to the at class(i have changed the code a lot but i can't get the desired results of fetching names and passing it to at class) and i get the response "<code>[{"readyState":4,"responseText":"\n\n{\"names\":\"Shikhar Bansal(bshikhar13131313@gmail.com),\"}","responseJSON":{"names":"Shikhar Bansal(bshikhar13131313@gmail.com),"},"status":200,"statusText":"OK"}]</code>" when i alert the results var.
  the code i tried so far:</p>
  
  <pre><code> tinymce.init({
    selector: 'textarea#wall_id_1',
    height: 300,
    theme: 'modern',
    resize: false,
    force_p_newlines: false,
    plugins: 'print preview powerpaste searchreplace autolink directionality advcode visualblocks visualchars fullscreen image link media template codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount tinymcespellchecker a11ychecker imagetools mediaembed  linkchecker contextmenu colorpicker textpattern help',
    toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify  | numlist bullist outdent indent  | removeformat',
    image_advtab: true,
    templates: [
      { title: 'Test template 1', content: 'Test 1' },
      { title: 'Test template 2', content: 'Test 2' }
    ],
    content_css: [
      '//fonts.googleapis.com/css?family=Lato:300,300i,400,400i',
      '//www.tinymce.com/css/codepen.min.css'
    ],
    setup: function(editor) {
          editor.on('keyup', function(e) {
      /*      
              var eli= $(editor.contentDocument.activeElement).prop('innerHTML');
  
              var txt=$(eli+'p').html();
            var txt1=$(eli+'span').html();
            var regex=new RegExp(/@+([a-zA-z!._-]+)/g);
             var match= regex.exec(txt); 
       //console.log(match);
     // alert(match);
   var names=load_Ajax(match[1]);
   return names;*/
            if(e.keyCode == 13 &amp;&amp; $(editor.contentDocument.activeElement).atwho('isSelecting'))
              return false;
          });
    return names;    
    },
  
    init_instance_callback: function(editor) {
  
            var results=new Array(); 
      var get_names= editor.on("keyup",function(e){
  
              var eli= $(editor.contentDocument.activeElement).prop('innerHTML');
  
              var txt=$(eli+'p').html();
            var txt1=$(eli+'span').html();
            var regex=new RegExp(/@+([a-zA-z!._-]+)/g);
             var match= regex.exec(txt); 
  
  
   $.ajax({
             url : "jsdropdown.php",
     data : {"uname":match[1]},
     async: false,
     complete:function(res){
        results.push(res);
        //results=res;
       // alert(JSON.stringify(res));
      //return res;
      },
      dataType: "json"
  });
   /*var names=$.when(load_Ajax(match[1])).done(function(response){
       return response;
   });*/
  
  
     alert(JSON.stringify(results));  
      }).responseJSON;
  
  
  
          $(editor.contentDocument.activeElement).atwho({at: "@", data: names});
  
    }
  
   });
  </code></pre>