一个文本框的正则表达式的最大和最小长度的字符 [英] RegEx Max and Min length characters for a Text Box
问题描述
我用Asp.net和C#。
I use Asp.net and C#.
我需要强制用户在TextBox控件之间只有4和128个字符的文本添加。
I need force the User to add in a TextBox Control only between 4 and 128 characters text.
我想用一个ValidationEx pression物业验证控件。
I would like to use a ValidationExpression Property for a Validation Control.
你能指出我出正确的正防爆pression?
注:我用这个code现在,但它似乎没有工作,如果正常有双空格或在TextBox断线
Notes: I'm using this code right now, but it seems not working properly if there are double spaces or break line in the TextBox
ValidationExpression="^.{4,128}$"
感谢您的时间对这个!
Thanks for your time on this!
推荐答案
您的前pression是正确的。只需使用 SINGLELINE
修改,使点也匹配换行符。
Your expression is correct. Just use the Singleline
modifier, to make the dot also match newline characters.
RegexOptions.Singleline
或者为内联修改
"^(?s)(.){4,128}$"
RegexOptions枚举结果
普通防爆pression选项
这篇关于一个文本框的正则表达式的最大和最小长度的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!