import * as moment from "moment/moment";
export function ruleNotValue(val, text) {
  return !!val || text || false;
}

export function ruleLengthValue(val, minLength, text) {
  return (val && val.length === minLength) || text || false;
}

export function ruleOptionalFields(val, minLength, text) {
  return !val || val.length === minLength || text || false;
}

export function ruleEmailValue(val, text) {
  const regExp = new RegExp(/^[^\s()<>@,;:/]+@\w[\w.-]+\.[a-z]{2,}$/i);
  return (val && val.length < 100 && regExp.test(val)) || text || false;
}

export function ruleMaxLength(val, maxLength, text) {
  return (!!val && val.length <= maxLength) || text || false;
}

export function ruleDateValue(val, text) {
  return (
    (val && !moment(val).isAfter(moment().format("YYYY-MM-DD"))) ||
    text ||
    false
  );
}
