class FormValidators {
  FormValidators._();

  static String? required(String? value, {String message = '请输入内容'}) {
    if (value == null || value.trim().isEmpty) return message;
    return null;
  }

  static String? email(String? value, {String message = '请输入有效邮箱'}) {
    if (value == null || value.trim().isEmpty) return null;
    final regex = RegExp(r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$');
    return regex.hasMatch(value.trim()) ? null : message;
  }

  static String? phoneCN(String? value, {String message = '请输入有效手机号'}) {
    if (value == null || value.trim().isEmpty) return null;
    final regex = RegExp(r'^1[3-9]\d{9}$');
    return regex.hasMatch(value.trim()) ? null : message;
  }

  static String? minLength(String? value, int min, {String? message}) {
    if (value == null || value.isEmpty) return null;
    return value.length >= min ? null : message ?? '至少输入 $min 个字符';
  }
}
