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

const validator = (record, value = '', formValues, form, opt = {}, isModalInputMappingItem) => {
  if ((!isEmpty(value) && typeof value !== 'string') || (!isModalInputMappingItem && (!isEmpty(value) && value.length > (opt.length || record.length)))) {
    return new Error((opt.message) || '格式错误');
  }
  if (opt.minLength && opt.minLength > 0) {
    if (!isEmpty(value) && value.length < opt.minLength) {
      return new Error('长度不能超过' + opt.minLength);
    }
  }
  return null;
};

export default validator;
