rxjs - Discard future returning observables : <p>So here is my observable code:</p>

<pre><code>  var suggestions =
        Rx.Observable.fromEvent(textInput, 'keyup')
          .pluck('target','value')
          .filter( (text) =&gt; {
              text = text.trim();
              if (!text.length) // empty input field
              {
                  this.username_validation_display("empty");
              }
              else if (!/^\w{1,20}$/.test(text))
              {
                  this.username_validation_display("invalid");
                  return false;
              }
              return text.length &gt; 0;
          })
          .debounceTime(300)
          .distinctUntilChanged()
          .switchMap(term =&gt; {
              return $.ajax({
                type: "post",
                url: "src/php/search.php",
                data: {
                  username: term,
                  type: "username"
                }
              }).promise();
            }
          );
  suggestions.subscribe(
    (r) =&gt;
    {
        let j = JSON.parse(r);
        if (j.length)
        {
            this.username_validation_display("taken");
        }
        else
        {
            this.username_validation_display("valid");
        }
    },
    function (e)
    {
        console.log(e);
    }
  );
</code></pre>

<p>The problem I have is when the input is empty I have a another piece of code that basically returns a 'error: empty input' but it gets overridden by the returning observable. So I was wondering if there was a way to disregard all observables if the <code>text.length</code> is 0, but also re-subscribe when the text length isn't zero.</p>

<p>I've thought about <code>unsubscribe</code> but don't know where to fit it in to try.</p>
