^[0-9]{10}$^ Assert position at the start of the string [0-9] Match a single character out of the list: in the range between 0 and 9 ォ[0-9]{10}サ {10} Exactly 10 times ォ{10} $ Assert position at the end of the string (or before the line break at the end of the string, if any)搂主,这个是没有错的,如果有错,那应该是你用法的问题
string strPattarn = @"^(\d{1,10})$"; Regex reg = new Regex(strPattarn); if (reg.IsMatch(textBox1.Text)) { MessageBox.Show(this, "OK"); }
{
try
{
decimal.Parse(decItem);
}
catch
{
return false;
} return true;
} private const string IS_NUMBER = @"(^[0-9]+$)";
private const string IS_YYYYMM_ICON = @"(^[1][8-9][0-9][0-9]/[0][1-9]+$)|(^[1][8-9][0-9][0-9]/[1][0-2]+$)|(^[2-9][0-9][0-9][0-9]/[0][1-9]+$)|(^[2-9][0-9][0-9][0-9]/[1][0-2]+$)";
private const string IS_YYYYMM = @"(^[1][8-9][0-9][0-9][0][1-9]+$)|(^[1][8-9][0-9][0-9][1][0-2]+$)|(^[2-9][0-9][0-9][0-9][0][1-9]+$)|(^[2-9][0-9][0-9][0-9][1][0-2]+$)";
private const string IS_HALF_WORD = @"(^(([!-/:-@[-`{-~])|([a-zA-Z0-9]))+$)";
[0-9] Match a single character out of the list: in the range between 0 and 9 ォ[0-9]{10}サ
{10} Exactly 10 times ォ{10}
$ Assert position at the end of the string (or before the line break at the end of the string, if any)搂主,这个是没有错的,如果有错,那应该是你用法的问题
Regex reg = new Regex(strPattarn);
if (reg.IsMatch(textBox1.Text))
{
MessageBox.Show(this, "OK");
}
但是仅用RegularExpressionValidator的话首尾的空格会被trim掉,全是空格相当于没有输入,这时正则表达式不起作用
我想你只要用RegularExpressionValidator验证控件,控件就会自动处理掉首尾的空格
,我想要不让它处理掉有点不大可能
Regex reg = new Regex(strPattarn);
if (reg.IsMatch(textBox1.Text))
{
MessageBox.Show(this, "OK");
}
try {
FoundMatch = Regex.IsMatch(SubjectString, "^(\\d{1,10})$");
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
try {
FoundMatch = Regex.IsMatch(textBox1.Text, "^(\\d{1,10})$");
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}
============================================================我的那些textbox不都是必須入力字段。但是問題現在問題已經被公司的leader解決了。謝謝各位。
特別感謝:fancyf(凡瑞)
感謝你給了我解決問題的方向。