src/Nuffle.php
private function _validate($input) {
    // has to be something we can calculate
    if ( !is_string($input) && !is_numeric($input) ) {
      throw new \Exception("Input must be an equation or a number.");
    }

    // no empty inputs
    if ( trim($input) === '' ) {
      throw new \Exception("Input can't be blank.");
    }

    // validate the input format
    if ( !preg_match("/^[\(\s]*(([1-9][0-9]*d[1-9][0-9]*)|\d+)[\s\)]*(\s*([\-\+\*\/])[\s\(]*(([1-9][0-9]*d[1-9][0-9]*)|\d+)\)*)*$/i", $input) ) {
      throw new \Exception("Invalid equation.");
    }

    // make sure the parens are balanced
    if ( !$this->_is_balanced($input) ) {
      throw new \Exception("Unbalanced parens.");
    }

    $this->input = $input;
  }
private function _validate($input) {
    // has to be something we can calculate
    if ( !is_string($input) && !is_numeric($input) ) {
      throw new \Exception("Input must be an equation or a number.");
    }

    // no empty inputs
    if ( trim($input) === '' ) {
      throw new \Exception("Input can't be blank.");
    }

    // validate the input format
    if ( !preg_match("/^[\(\s]*(([1-9][0-9]*d[1-9][0-9]*)|\d+)[\s\)]*(\s*([\-\+\*\/])[\s\(]*(([1-9][0-9]*d[1-9][0-9]*)|\d+)\)*)*$/i", $input) ) {
      throw new \Exception("Invalid equation.");
    }

    // make sure the parens are balanced
    if ( !$this->_is_balanced($input) ) {
      throw new \Exception("Unbalanced parens.");
    }

    $this->input = $input;
  }
private function _validate ( $ input ) { // has to be something we can calculate if ( ! is_string ( $ input ) && ! is_numeric ( $ input ) ) { throw new \ Exception ( "Input must be an equation or a number." ) ; } // no empty inputs if ( trim ( $ input ) === '' ) { throw new \ Exception ( "Input can't be blank." ) ; } // validate the input format if ( ! preg_match ( "/^[\(\s]*(([1-9][0-9]*d[1-9][0-9]*)|\d+)[\s\)]*(\s*([\-\+\*\/])[\s\(]*(([1-9][0-9]*d[1-9][0-9]*)|\d+)\)*)*$/i" , $ input ) ) { throw new \ Exception ( "Invalid equation." ) ; } // make sure the parens are balanced if ( ! $ this -> _is_balanced ( $ input ) ) { throw new \ Exception ( "Unbalanced parens." ) ; } $ this -> input = $ input ; }
Validate user input

@param  string $input User input
@return void
Validate user input