俺的一个正则表达式:[0-9]{0,10}
俺想要做到只能输入10位数字,可现在还能输入10位空格,不知咋该。特地求教,谢谢诸位!

解决方案 »

  1.   

    public static bool IsDecimail(string decItem)
    {
    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]))+$)";
      

  2.   

    ^[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)搂主,这个是没有错的,如果有错,那应该是你用法的问题
      

  3.   

    string strPattarn = @"^(\d{1,10})$";
    Regex reg = new Regex(strPattarn);
    if (reg.IsMatch(textBox1.Text))
    {
         MessageBox.Show(this, "OK");
    }
      

  4.   

    ^[0-9]{0,10}$这个表达式本身没问题,它不允许输入空格
    但是仅用RegularExpressionValidator的话首尾的空格会被trim掉,全是空格相当于没有输入,这时正则表达式不起作用
      

  5.   

    谢谢各位!如果俺不想让RegularExpressionValidator自动trim空格,那该怎么做?谢谢!
      

  6.   

    cchon(中文字符)应该是正确的测试reg,建议使用RegexDesigner.NET来测试,很方便的
      

  7.   

    如果俺不想让RegularExpressionValidator自动trim空格,那该怎么做?
    我想你只要用RegularExpressionValidator验证控件,控件就会自动处理掉首尾的空格
    ,我想要不让它处理掉有点不大可能
      

  8.   

    string strPattarn = @"^(\d{1,10})$";
    Regex reg = new Regex(strPattarn);
    if (reg.IsMatch(textBox1.Text))
    {
         MessageBox.Show(this, "OK");
    }
      

  9.   

    bool FoundMatch = false;
    try {
    FoundMatch = Regex.IsMatch(SubjectString, "^(\\d{1,10})$");
    } catch (ArgumentException ex) {
    // Syntax error in the regular expression
    }
      

  10.   

    bool FoundMatch = false;
    try {
    FoundMatch = Regex.IsMatch(textBox1.Text, "^(\\d{1,10})$");
    } catch (ArgumentException ex) {
    // Syntax error in the regular expression
    }
      

  11.   

    再用一个RequiredFieldValidator,就可以避免只输空格了
      

  12.   

    to: fancyf(凡瑞) 再用一个RequiredFieldValidator,就可以避免只输空格了
    ============================================================我的那些textbox不都是必須入力字段。但是問題現在問題已經被公司的leader解決了。謝謝各位。
    特別感謝:fancyf(凡瑞) 
    感謝你給了我解決問題的方向。