【发布时间】:2014-03-11 21:34:08
【问题描述】:
我正在使用 FluentValidation 并尝试创建一个规则,如果字符串中有任何空格(即用户名),则会引发错误。
我已经查看了这些 SO,但似乎没有用,我确定我的语法有点不对劲?
What is the Regular Expression For "Not Whitespace and Not a hyphen" 和 What is the Regular Expression For "Not Whitespace and Not a hyphen"
RuleFor(m => m.UserName).NotEmpty().Length(3, 15).Matches(@"/^\S\z/");
或
RuleFor(m => m.UserName).NotEmpty().Length(3, 15).Matches(@"[^\s]");
这些似乎都不起作用。其他规则不为空,长度在 3 到 15 个字符之间。
【问题讨论】:
标签: c# regex fluentvalidation