简体   繁体   English

C#RegularExpressionValidator修剪和计数

[英]C# RegularExpressionValidator Trim and Count

I have a textbox with a RegularExpressionValidator. 我有一个带有RegularExpressionValidator的文本框。 I want to require the user to enter at least n characters. 我想要求用户至少输入n个字符。 I'd also like to remove whitespace both at the start and end of the textbox. 我还想在文本框的开头和结尾处删除空格。 I'd still like to allow spaces within the textbox, I just want to remove the excess at the beginning and end. 我仍然想在文本框中保留空格,我只想删除开头和结尾的多余部分。

I basically don't know how to combine the trim regex and the count together for use in a REV. 我基本上不知道如何将修整正则表达式和计数结合在一起以用于REV。

trim: ^\s*((?:[\S\s]*\S)?)\s*$
count: .{10}.*

I basically want to know if the input, after leading and trailing whitespace is removed, is greater than n characters. 我基本上想知道在删除前导和尾随空格后,输入是否大于n个字符。

You could use word boundaries to ignore the whitespace in the beginning, accept 10 characters, then end with another word boundary with a pattern like this: 您可以使用单词边界在开始时忽略空格,接受10个字符,然后以如下模式结束另一个单词边界:

\b.{10}\b

Be sure to also use a RequiredFieldValidator to cover empty inputs since the RegularExpressionValidator does not handle such cases. 确保也使用RequiredFieldValidator覆盖空的输入,因为RegularExpressionValidator无法处理这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM