我编写此代码来验证用户名是否符合给定条件,有没有人看到我如何将2个RegEx合并为一个?代码是c#
/// <summary>
/// Determines whether the username meets conditions.
/// Username conditions:
/// Must be 1 to 24 character in length
/// Must start with letter a-zA-Z
/// May contain letters, numbers or '.','-' or '_'
/// Must not end in '.','-','._' or '-_'
/// </summary>
/// <param name="userName">proposed username</param>
/// <returns>True if the username is valid</returns>
private static Regex sUserNameAllowedRegEx = new Regex(@"^[a-zA-Z]{1}[a-zA-Z0-9\._\-]{0,23}[^.-]$", RegexOptions.Compiled);
private static Regex sUserNameIllegalEndingRegEx = new Regex(@"(\.|\-|\._|\-_)$", RegexOptions.Compiled);
public static bool IsUserNameAllowed(string userName)
{ …Run Code Online (Sandbox Code Playgroud)