求 正则.文本框可以输入 英文 数字 还有空格,其他都不允许输入比如
lnt tadd2 输入成立
lint 成立
222 不成立
空格 不成立
lnt tadd2 输入成立
lint 成立
222 不成立
空格 不成立
解决方案 »
- 如何在一个变量值里加空格,比如这样:我爱你,最后结果是:我 爱 你 ??
- 求个vs2008的msdn\setup文件夹
- Winform中怎样再开一个线程
- 获取 datagrid 行列值,以及列名称
- 在c#里怎么画一条横线?
- 一个WinForm处理Message的问题,困惑!(请各位高手看看)
- 关于打开文件
- 在datatable里如何操作这样的需求呢
- 用VS2012 ,C#写的一个窗体程序,是基于.net4.5的,Release之后在别的电脑上(另一台电脑是win7,也装了.net4.5,但没装VS)打不开,
- 高手进,高分求救,很晕啊,为什么我的new Form3().Show()无法弹出窗口,只在状态栏上有显示。
- 可以将窗体,嵌入到一个窗体中吗?比如让主窗体的右侧,灵活的嵌入不同的其他窗体?
- ★★★请教:如何判断表的某列是不是自增列??
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
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
*/
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
*/
//在改下,刚少了个数字和空格也不成立
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();