求 正则.文本框可以输入 英文 数字 还有空格,其他都不允许输入比如
lnt tadd2  输入成立 
lint       成立
222        不成立
空格       不成立

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.IO;
    namespace sxLdfang
    {
        class Program
        {
            static void Main(string[] args)
            {
                string html = @"how are you";
                string pattern = @"(?i)(?=[^a-z]*[a-z])^[a-z0-9\s]+$";
                MatchCollection mc = Regex.Matches(html, pattern);
                foreach (Match m in mc)
                {
                    Console.WriteLine(m.Value);
                }
                Console.ReadKey();
            }
        }
    }
    运行结果:
    how are you
      

  2.   


                List<string> list = new List<string> { "lnt tadd2", "lint", " " };
                Regex reg = new Regex(@"(?i)^(?![^a-z]+$)(?!\D+$)(?!\s+$)[a-z\d\s]+$");
                foreach (string s in list)
                {
                    Console.WriteLine(reg.Match(s).Success);
                }
                Console.ReadLine();
    /*
    true
    false
    false
    */
      

  3.   


                List<string> list = new List<string> { "lnt tadd2", "lint ", " ", "222" };
                Regex reg = new Regex(@"(?i)^(?!\d+$)(?!\s+$)[a-z\d\s]+$");
                foreach (string s in list)
                {
                    Console.WriteLine(reg.Match(s).Success);
                }
                Console.ReadLine();
    /*
    true
    true
    false
    false
    */
      

  4.   

    //数字加空格或只有数字或只有空格都不成立
    //在改下,刚少了个数字和空格也不成立
                List<string> list = new List<string> { "lnt tadd2 ","aa", "lint ", " ", "222 " };
                Regex reg = new Regex(@"(?i)^(?![\d\s]+$)[a-z\d\s]+$");
                foreach (string s in list)
                {
                    Console.WriteLine(reg.Match(s).Success);
                }
                Console.ReadLine();
      

  5.   

    sxldfang 正确,谢谢也谢谢楼上的。