2012-06-07 205 views
0

我想要制作一个必须释放一个数字和一个字母表的正则表达式。验证正则表达式必须包含字母数字

onlyText不会数学。但是onlyText123比赛。

+0

http://stackoverflow.com/questions/336210/regular-expression-for-alphanumeric-and-underscores此减号下划线。 –

回答

3

在这里你去

^(?=.*[a-zA-Z])(?=.*[\d]).*$ 

的关键是使用一种称为环视技术

0

你可以尝试这样的事情

String p= "\\w*([a-zA-Z]\\d|\\d[a-zA-Z])\\w*"; 

System.out.println("1a".matches(p));//true 
System.out.println("a1".matches(p));//true 
System.out.println("1".matches(p));//false 
System.out.println("a".matches(p));//false 

([a-zA-Z]\\d|\\d[a-zA-Z]) ==信然号或号码然后写信

和之前和之后它可以(但不一定是)字母和数字(\\w

相关问题