请教一个正则表达式 请问一个字符串 不能存在冒号 且头尾不能出现空字符 空格出现在中间是允许的这个正则怎么写呢谢谢各位了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static void main(String[] args) { //不能存在冒号 且头尾不能出现空字符 空格出现在中间是允许的 String arr[] = { " aa", "aa ", "aa:bb", "aa bb" }; for(int i=0;i<arr.length;i++){ System.out.println(arr[i].matches("[^\\s:][^:]*[^\\s:]")); } } aaa:bbbbbb:ccc:这样都行啊。。是不能存在冒号! <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <input id="inputbox" type="text" value="" /> <script> var reg = /^[^\:\s][^\:]*[^\:\s]$/; document.getElementById('inputbox').onchange = function(){ alert(reg.test(this.value)); } </script> </body></html> 如果要限定只能输入数字、字母、下划线: ^(?!\s)[\w^:]*(?!\s)$如果要输入汉字以及其他乱码: ^(?!\s)[^:]*[^:\s](?!\s)$因该不会错了... <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <input id="inputbox" type="text" value="" /> <script> var reg1 = /^[^\:\s][^\:]*[^\:\s]?$|^[^\s\:]$/, reg2 = /^(?=\S)(?=[\s\S]*\S$)[^\:]*$/; document.getElementById('inputbox').onchange = function(){ alert(reg1.test(this.value)+', '+reg2.test(this.value)); } </script> </body></html>2个正则都可以 正则 /[\x00-\xff]/ 单字节匹配的问题 有关运算符||的问题和赋值单位 验证正整数 javascript 文本框自动计算 不确定alert提示框,方法继续执行问题 怎样在表格的倒数第二行动态增加一行????? 求救:如何让网址不变? 高手来看看%%%%%%%%%%%%%% 为什么我的htc在Weblogic 7中不能生效? window.opener.location.reload();怎样才能不弹出“重试”“取消”对话框?? ie8下showModalDialog为什么无效呢 数据类型的判断
public static void main(String[] args) {
//不能存在冒号 且头尾不能出现空字符 空格出现在中间是允许的
String arr[] = {
" aa",
"aa ",
"aa:bb",
"aa bb"
};
for(int i=0;i<arr.length;i++){
System.out.println(arr[i].matches("[^\\s:][^:]*[^\\s:]"));
}
}
bbb:ccc:
这样都行啊。。
是不能存在冒号!
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<input id="inputbox" type="text" value="" />
<script>
var reg = /^[^\:\s][^\:]*[^\:\s]$/;
document.getElementById('inputbox').onchange = function(){
alert(reg.test(this.value));
}
</script>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<input id="inputbox" type="text" value="" />
<script>
var reg1 = /^[^\:\s][^\:]*[^\:\s]?$|^[^\s\:]$/,
reg2 = /^(?=\S)(?=[\s\S]*\S$)[^\:]*$/;
document.getElementById('inputbox').onchange = function(){
alert(reg1.test(this.value)+', '+reg2.test(this.value));
}
</script>
</body>
</html>2个正则都可以