Aru*_*mar 2 c# regex asp.net-mvc
我正在寻找一个正则表达式,不允许字符串以'!'开头 或'='.这是我目前的代码,我只添加了'='的代码,但这些代码不起作用.
[RegularExpression("^(?!=)", ErrorMessageResourceName="Error_StringStartWith", ErrorMessageResourceType= typeof(CommonStrings))]
public String FirstName { get; set; }
Run Code Online (Sandbox Code Playgroud)
您正在寻找 (?![!=]).*
(?! // Negative lookahead
[!=] // Match either ! or = literal
)
.* // Match any token zero to unlimited times
Run Code Online (Sandbox Code Playgroud)
@Rawling向我指出,没有必要断言字符串的开头,所以我删除了它.