Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想出了一个正则表达式,可以防止用户使用两个连续的破折号。它们几乎可以进入任何其他可以想象的模式。我尝试实施的唯一其他标准是防止用户在文本框中的任何位置输入任何空白。这是我用于防止双破折号的表达式:
[RegularExpression(@"^(?:(?!--).)*$", ErrorMessage = "No double dashes please")]
有人可以帮我在这个表达式中添加阻止用户在文本框中任何地方输入空格的功能吗
谢谢
为了防止空格,您可以\s使用交替添加到现有的负前瞻:
\s
@"^(?:(?!--|\s).)*$"