我正在寻找一个不允许字符串以 '!' 开头的正则表达式或“=”。这是我目前的代码,其中我只添加了不起作用的“=”代码。
[RegularExpression("^(?!=)", ErrorMessageResourceName="Error_StringStartWith", ErrorMessageResourceType= typeof(CommonStrings))]
public String FirstName { get; set; }
最佳答案
您正在寻找 (?![!=]).*
(?! // Negative lookahead
[!=] // Match either ! or = literal
)
.* // Match any token zero to unlimited times
@Rawling 向我指出,没有必要断言字符串的开头,所以我已将其删除。
关于c# - 字符串不应以 !或 = 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30068292/