How to release the reference to HTML to the different text



  • The formulas for correct entry are checked. Under the formula, we need to indicate a ^ position where there is an incorrect entry.

    (a+b) - (a-b)
    

    (a+b - (a-b
    ^ ^



  • Just check the number of open and closed brackets. If the numbers don't match, there's a mistake. But the function only finds one mistake.

    Take an error @Sergiks

    $('input').on('change', function() {
      var value = this.value;
      var opened = 0;
      var last = 0;
    

    for(var i=0, sp=value.split(""); i < sp.length; i++) {
    if(sp[i] == "(") {
    last = i;
    opened++;
    }

    if(sp[i] == ")"){
      last = i;
      opened--;
    }
    
    if(opened &lt; 0) {
       show_error(last);
       break;
    }
    

    }

    if(opened != 0) {
    show_error(last);
    }

    });

    function show_error(sym_no) {
    alert(sym_no);
    }

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <input>




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2