/**
 * Created by baoyinghai on 12/5/16.
 */
import validation from '../../../../utils/validation';
import { isEmpty } from '../../../../utils/EmptyUtils';

const validator = (record, value, formValues, form, opt = {}) => {
  const handle = validation.isTerm;
  if (!isEmpty(value) && !handle(value)) {
    // record.formValidate.validateType
    return new Error((opt.message) || '格式错误');
  }
  const { before, after } = opt;
  if (before && value > before) {
    return new Error('在' + before + '之前');
  } else if (after && value < after) {
    return new Error('在' + after + '之后');
  }
  return null;
};

export default validator;
