namespace SimpleAdmin.Application; /// /// 统一校验入职业务中的可编辑编码,避免非法字符或超长内容落到数据库后才报 500。 /// internal static class OnboardingCodeValidator { /// /// 规范化并校验业务编码。编码必须以字母开头,可包含字母、数字、点、下划线和短横线。 /// public static string Normalize(string code, string fieldName, int maxLength) { var normalized = code?.Trim(); if (string.IsNullOrWhiteSpace(normalized)) throw Oops.Bah($"{fieldName}不能为空"); if (normalized.Length > maxLength) throw Oops.Bah($"{fieldName}长度不能超过 {maxLength} 个字符"); if (!global::System.Text.RegularExpressions.Regex.IsMatch( normalized, @"^[A-Za-z][A-Za-z0-9._-]*$")) { throw Oops.Bah($"{fieldName}必须以字母开头,只能包含字母、数字、点、下划线和短横线"); } return normalized; } }