字母数字不能使用下划线

本文关键字:下划线 不能 数字 | 更新日期: 2023-09-27 17:59:14

我正在使用以下REGEX,我需要的是只接受具有以下条件的字母数字值

1.Should not start with number
2.Accept underscore between character 
3.Can have space after the value

例如

aa_bba1_a2

我尝试了以下操作,但效果不佳:

@"^[a-zA-Z0-9]+(_.[a-zA-Z0-9]+)*$",

字母数字不能使用下划线

@"^[a-zA-Z][a-zA-Z0-9_.]+'s?$"

使用此正则表达式。

您的正则表达式有几个缺陷

  • ^[a-zA-Z0-9]+将允许在测试字符串的开头使用数字
  • 末端没有空间,因此不允许有空间

此处演示:http://regex101.com/r/xG7cT9