siv*_*iva 1 c# regex compact-framework
任何人都可以使用正则表达式帮助C#代码验证只接受100到999999之间的数字的文本框
谢谢,Lui.
你不需要正则表达式.
int n;
if (!int.TryParse(textBox.Text.Trim(), out n) || n<100 || n>999999)
{
// Display error message: Out of range or not a number
}
Run Code Online (Sandbox Code Playgroud)
编辑:如果CF是目标,那么你不能使用int.TryParse().int.Parse()反而回退并键入一些更错误的代码:
int n;
try
{
int n = int.Parse(textBox.Text.Trim());
if (n<100 || n>999999)
{
// Display error message: Out of range
}
else
{
// OK
}
}
catch(Exception ex)
{
// Display error message: Not a number.
// You may want to catch the individual exception types
// for more info about the error
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2587 次 |
| 最近记录: |