日期:2014-05-19  浏览次数:21124 次

项目开发中,急求一个正则表达式
项目开发中,急需用永正则表达式来验证一段string,条件是:字符串长度至少要8,字符串中至少包含一个大写字母和一个数字。不知道这样的表达式该怎样写,请各位帮帮忙,谢谢各位。

------解决方案--------------------
帮顶
------解决方案--------------------
用在什么环境下,验证控件中,还是程序里

对其它字符是否有限制

试下

^(?!\D+$)(?![^A-Z]+$).{8,}$
------解决方案--------------------
过客是正则高手,lz试试吧,还有你用的是C#写还是JS写?
------解决方案--------------------
帮顶,顺便学习!
------解决方案--------------------
(?=.{8})\b.*([A-Z].*\d|\d.*[A-Z]).*\b
------解决方案--------------------
有分就接!
------解决方案--------------------
(?=.{8})\b.*([A-Z].*\d|\d.*[A-Z]).*\b

------解决方案--------------------
if (this.textBox1.Text.Length > = 8 && System.Text.RegularExpressions.Regex.IsMatch(this.textBox1.Text, @ "\b.*([A-Z].*\d|\d.*[A-Z]).*\b "))
{
MessageBox.Show( "ok ");
}
else
{
MessageBox.Show( "failed ");
}
------解决方案--------------------
lookaround 里不能用 {3,} 这样的不定长,所以长度判断用 string.Length 吧
------解决方案--------------------
过客的正则真的好强
------解决方案--------------------
各位大侠都能把 about a date that will live in infamy: 12/7/41 找出来
这里面没有大写字母
过客太强了 (?![^A-Z]+$) 看不懂 解释一下吧

------解决方案--------------------
强人。
------解决方案--------------------
测试了一下过客的表达式,对没有大写字母的也能匹配
------解决方案--------------------
楼上给个例子,谢谢
------解决方案--------------------
6abcdefg也能匹配出来
------解决方案--------------------
只是一般的正则验正工具,上面wzc999_(一流冷涧) 也有提到
------解决方案--------------------
我正则工具,.net的winform和webform都测了,你在程序里测一下吧
------解决方案--------------------
没分资料下不了啊
------解决方案--------------------
在哪个地方能够加分啊
------解决方案--------------------
JF 顺便学习中
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Text.RegularExpressions;

namespace WebSnatch
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}

private void simpleButton1_Click(object sender, EventArgs e)
{
Regex reg = new Regex(@ "^(?!\D+$)(?![^A-Z]+$).{8,}$ ", RegexOptions.IgnoreCase);
StringBuilder sb = new StringBuilder( "about a date that will live in infamy: 12/7/41. ");
MatchCollection mc = reg.Matches(sb.ToString());