lib/recordCheck/data-check-number.js
function parseNumberString(numberString, type, decimalSeparator) {
  let result;
  if (numberString !== undefined) {
    if (typeof numberString === 'string') {
      // The given value is a string

      if (decimalSeparator === ',') {
        numberString = numberString.replace(/\./g, '');
        numberString = numberString.replace(/,/g, '\.');
      } else {
        numberString = numberString.replace(/,/g, '');
      }


      if (numberString.match(/[^0-9\.]/g)) {
        // check if the string contains NO number values
        result = 'NUMBER_NOT_VALID';
      } else if ((numberString.match(/\./g) || []).length > 1) {
        // proof that only one decimal separator exists
        result = 'NUMBER_NOT_VALID';
      } else {
        if (type === 'float') {
          result = parseFloat(numberString);
          if (result === undefined) {
            result = 'NOT_FLOAT';
          }
        } else if (type === 'integer') {
          if (numberString.match(/\./g)) {
            result = 'NOT_INTEGER';
          } else {
            result = parseInt(numberString);
            if (result === undefined) {
              result = 'NOT_INTEGER';
            }
          }
        } else if (type === 'number') {
          result = parseFloat(numberString);
          if (result === undefined) {
            result = parseInt(numberString);
            result = 'NUMBER_NOT_VALID';
          }
        }
      }
    } else if (typeof numberString === 'number') {
      result = numberString;
    } else {
      result = 'NUMBER_NOT_VALID';
    }
  }
  return result;
}
function parseNumberString(numberString, type, decimalSeparator) {
  let result;
  if (numberString !== undefined) {
    if (typeof numberString === 'string') {
      // The given value is a string

      if (decimalSeparator === ',') {
        numberString = numberString.replace(/\./g, '');
        numberString = numberString.replace(/,/g, '\.');
      } else {
        numberString = numberString.replace(/,/g, '');
      }


      if (numberString.match(/[^0-9\.]/g)) {
        // check if the string contains NO number values
        result = 'NUMBER_NOT_VALID';
      } else if ((numberString.match(/\./g) || []).length > 1) {
        // proof that only one decimal separator exists
        result = 'NUMBER_NOT_VALID';
      } else {
        if (type === 'float') {
          result = parseFloat(numberString);
          if (result === undefined) {
            result = 'NOT_FLOAT';
          }
        } else if (type === 'integer') {
          if (numberString.match(/\./g)) {
            result = 'NOT_INTEGER';
          } else {
            result = parseInt(numberString);
            if (result === undefined) {
              result = 'NOT_INTEGER';
            }
          }
        } else if (type === 'number') {
          result = parseFloat(numberString);
          if (result === undefined) {
            result = parseInt(numberString);
            result = 'NUMBER_NOT_VALID';
          }
        }
      }
    } else if (typeof numberString === 'number') {
      result = numberString;
    } else {
      result = 'NUMBER_NOT_VALID';
    }
  }
  return result;
}
function parseNumberString ( numberString , type , decimalSeparator ) { let result ; if ( numberString !== undefined ) { if ( typeof numberString === 'string' ) { // The given value is a string if ( decimalSeparator === ',' ) { numberString = numberString . replace ( / \. / g , '' ) ; numberString = numberString . replace ( / , / g , '\.' ) ; } else { numberString = numberString . replace ( / , / g , '' ) ; } if ( numberString . match ( / [^0-9\.] / g ) ) { // check if the string contains NO number values result = 'NUMBER_NOT_VALID' ; } else if ( ( numberString . match ( / \. / g ) || [ ] ) . length > 1 ) { // proof that only one decimal separator exists result = 'NUMBER_NOT_VALID' ; } else { if ( type === 'float' ) { result = parseFloat ( numberString ) ; if ( result === undefined ) { result = 'NOT_FLOAT' ; } } else if ( type === 'integer' ) { if ( numberString . match ( / \. / g ) ) { result = 'NOT_INTEGER' ; } else { result = parseInt ( numberString ) ; if ( result === undefined ) { result = 'NOT_INTEGER' ; } } } else if ( type === 'number' ) { result = parseFloat ( numberString ) ; if ( result === undefined ) { result = parseInt ( numberString ) ; result = 'NUMBER_NOT_VALID' ; } } } } else if ( typeof numberString === 'number' ) { result = numberString ; } else { result = 'NUMBER_NOT_VALID' ; } } return result ; }
Parses a string and try to convert it in a valid number.
If the string does not match a valid number it will return the error message, else the parsed number.
@param numberString The string to be checked
@param type The expected type ["float", "integer", "number"]
@param decimalSeparator The used decimal separator.
Parses a string and try to convert it in a valid number . If the string does not match a valid number it will return the error message else the parsed number .