[英]Detect that textbox has one number and one upper letter
Hi I need to use regular expressions in C# to validate a TextBox. 嗨我需要在C#中使用正则表达式来验证TextBox。
Regular expressions should validate that the textbox has one number and one uppercase letter 正则表达式应验证文本框是否包含一个数字和一个大写字母
My code is: 我的代码是:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator"
ValidationExpression="[A-Z a-z 0-9]*[0-1]+[A-z]+"></asp:RegularExpressionValidator>
but it's not allowing 但它不允许
nameA123
Where is my error? 我的错误在哪里?
Use this regex: 使用这个正则表达式:
^(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$
In the regex demo , you can add strings to see if they match. 在正则表达式演示中 ,您可以添加字符串以查看它们是否匹配。
Explanation 说明
^
anchor asserts that we are at the beginning of the string ^
anchor断言我们位于字符串的开头 (?=.*[AZ])
asserts that at it is possible to match some chars then an uppercase letter 前瞻(?=.*[AZ])
断言可以匹配一些字符然后一个大写字母 (?=.*[0-9])
asserts that at it is possible to match some chars then a digit 前瞻(?=.*[0-9])
断言,有可能匹配一些字符,然后匹配一个数字 [a-zA-Z0-9]+
matches letters and digits [a-zA-Z0-9]+
匹配字母和数字 $
anchor asserts that we are at the end of the string $
anchor断言我们在字符串的末尾 Reference 参考
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.