求允许输入英文的正则(有英文的基础上可以包括空格,以及数字)

lifeixie 2011-08-10 09:38:06
求 正则.

文本框可以输入 英文 数字 还有空格,其他都不允许输入

比如
lnt tadd2 输入成立
lint 成立
222 不成立
空格 不成立
...全文
349 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lifeixie 2011-08-10
  • 打赏
  • 举报
回复
sxldfang 正确,谢谢

也谢谢楼上的。
huangwenquan123 2011-08-10
  • 打赏
  • 举报
回复


//数字加空格或只有数字或只有空格都不成立
//在改下,刚少了个数字和空格也不成立
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();
啾啾我 2011-08-10
  • 打赏
  • 举报
回复
学习…………
huangwenquan123 2011-08-10
  • 打赏
  • 举报
回复

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
*/
huangwenquan123 2011-08-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lifeixie 的回复:]
是单独输数字不成立
单独输空格也不成立
但是单独输字母是成立的

上面正确

数字 + 空格不成立

字母 + (空格 或 数字)任意一个或者一起都成立
[/Quote]咦 字母加任意数字成立的话要重新改一下!
huangwenquan123 2011-08-10
  • 打赏
  • 举报
回复

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
*/
sxldfang 2011-08-10
  • 打赏
  • 举报
回复
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
lifeixie 2011-08-10
  • 打赏
  • 举报
回复
是单独输数字不成立
单独输空格也不成立
但是单独输字母是成立的

上面正确

数字 + 空格不成立

字母 + (空格 或 数字)任意一个或者一起都成立
porschev 2011-08-10
  • 打赏
  • 举报
回复

看你给出的几个便子。。。

是单独输数字不成立
单独输空格也不成立
但是单独输字母是成立的

是这个意思吗?

110,549

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧