相关疑难解决方法(0)

正则表达式 - 没有特殊字符

我正在使用正则表达式来验证用户名

^[a-zA-Z]+\.[a-zA-Z]{4,10}^'
Run Code Online (Sandbox Code Playgroud)

不幸的是,如果值包含特殊字符,则不会影响 !@#$%^&*)(':;

我很乐意为正则表达式提供一些帮助:

  • 仅限字母数字(a-zA-Z0-9)
  • 长度在4到10个字符之间.

regex alphanumeric special-characters username

10
推荐指数
2
解决办法
6万
查看次数

创建一个RegEx以验证用户名

我编写此代码来验证用户名是否符合给定条件,有没有人看到我如何将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)

c# regex

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

regex ×2

alphanumeric ×1

c# ×1

special-characters ×1

username ×1