validationMethods.js 2.2 KB
export default class Validation{

  validateEmail (value) {
     // regex from http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
     var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
     return re.test(value);
  };

  // containsNoSpecialCharacters(str){
  //  return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);
  // }

  noSpecialChars(str){
    str = String(str);
   return !/[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g.test(str);
  }

  noQwertysAllowed (str){
    str = str.toLowerCase();
    if(str.toLowerCase().indexOf("qwerty") >-1){
      return false;
    } else{
      return true;
    }
  }

  passwordValidation (str){
    if(str.length <6){
      return false;
    } else{
      return true;
    }
  }

  isNumberOnly(str){
      if(!/^\d+$/.test(str)){
        return false;
      }else {
        return true;
      }
  }
  isPositiveNotZeroNumber(str){
    str = parseFloat(str);
      if(str <=0){
        return false;
      }else {
        return true;
      }
  }
  isNumeric(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
  }

  isValidACN(str){
    str = String(str);
    //Remove any whitespace.
    str = str.replace(/\s+/g, '');
    console.log(str);
    console.log(str.length);
    if(/^\d+$/.test(str) && str.length ==9){
      return true;
    } else{
      return false;
    }
  }
  isValidShortCode(str){
    str = String(str);
    console.log(str);
    if(str.length < 5 && str.length >2){
      return true;
    } else{
      return false;
    }
  }
  containsNumbers (str){
    if(/\d/g.test(str)){
      return true;
    }else{
      return false;
    }
  }
  isInt(n){
    console.log(typeof Number(n));
      return Number(n) % 1 === 0;
  }

  isFloat(n){
      return Number(n) % 1 !== 0;
  }
  decimalPlaces(num) {
    num = parseFloat(num);
    var match = (''+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
    if (!match) { return 0; }
    return Math.max(
         0,
         // Number of digits right of decimal point.
         (match[1] ? match[1].length : 0)
         // Adjust for scientific notation.
         - (match[2] ? +match[2] : 0));
  }
};