flybridy
2017-12-01 07:21java正则包含大小写字母数字怎么写
要写一个正则 密码至少包含大写字母,小写字母,数字,且不少于8位。我在js里面是可以执行的。如下:
function test(){
//var text="index.aspx?test=1&ww=2&www=3"; //
var text= document.getElementById("test1").value;
var re =/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/;
var result= re.test(text);
if(result)
{
alert("ok");
}else
{
alert("密码至少包含大写字母,小写字母,数字,且不少于8位");
}
}。
2.但是项目结构原因,不好在js中添加,必须在后台java里面写,我现在写的:
public class Test {
public static void main(String args[]){
String reg="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}/$";
System.out.println(startCheck(reg,"12313"));
}
public static boolean startCheck(String reg,String string)
{
boolean tem=false;
Pattern pattern = Pattern.compile(reg);
Matcher matcher=pattern.matcher(string);
tem=matcher.matches();
return tem;
}
}
报错信息:Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 41
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}/$
,这个js跟java里面的正则一直搞不清楚,求解
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 高分悬赏:怎么使用Java语言过滤所有非法的字符,非法的字符是指,除了大小写字母和数字以外的其余字符
- 开发语言
- 3个回答
- java正则表达式-必须包含字母大小写,数字,特殊字符怎么写
- 正则表达式
- 0个回答
- 求一个JAVA正则表达式
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- 请帮忙解决Html字符串转换成xml的问题,谢谢
- oo
- 0个回答
- 小白请问下32位数字及符号的正则表达式怎么写?
- java
- 2个回答