我正在使用正则表达式来验证用户名
^[a-zA-Z]+\.[a-zA-Z]{4,10}^'
Run Code Online (Sandbox Code Playgroud)
不幸的是,如果值包含特殊字符,则不会影响 !@#$%^&*)(':;
我很乐意为正则表达式提供一些帮助:
a-zA-Z0-9)我编写此代码来验证用户名是否符合给定条件,有没有人看到我如何将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)