<script language="javascript"> function check(obj){ var val = obj.value; if(val.length < 3){ return false; } var len = 1; var old = val[0]; for(var i in val){ if(old == val[i]){ ++len; }else{ old = val[i]; len = 1; } } if(len > 2){ alert('error input'); } } </script> <input type="text" onkeyup="check(this)">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head><body> <input id="t" type="text" /> <input id="btn" type="button" value="click me" /><script> document.getElementById('btn').onclick = function(){ var value = document.getElementById('t').value,count = 0;
for(var i = 0; i < value.length; i++){ var _char = value.charAt(i); if(_char == value.charAt(i + 1)){ count++; }else{ count = 0; }
function check(obj){
var val = obj.value;
if(val.length < 3){
return false;
}
var len = 1;
var old = val[0];
for(var i in val){
if(old == val[i]){
++len;
}else{
old = val[i];
len = 1;
}
}
if(len > 2){
alert('error input');
}
}
</script>
<input type="text" onkeyup="check(this)">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<input id="t" type="text" />
<input id="btn" type="button" value="click me" /><script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('t').value,count = 0;
for(var i = 0; i < value.length; i++){
var _char = value.charAt(i);
if(_char == value.charAt(i + 1)){
count++;
}else{
count = 0;
}
if(count > 2){
alert('连续一样的超过3个');
}
}
};
</script></body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<input id="t" type="text" />
<input id="btn" type="button" value="click me" /><script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('t').value,count = 0;
for(var i = 0; i < value.length; i++){
var _char = value.charAt(i);
var _next = value.charAt(i + 1)?value.charAt(i + 1):_char;
if(_char == _next){
count++;
}
if(count > 2){
alert('连续一样的超过3个');
}
}
};
</script></body>
</html>
var value = document.getElementById('t').value;
for(var i = 0; i < value.length-2; i++){
if(value.charAt(i) ==value.charAt(i+1) &&value.charAt(i) ==value.charAt(i+2)
alert('连续一样的超过3个');
}
}抢分的来了哈~
<head>
<title></title>
</head>
<body>
<input type="text" onkeyup="checkMultiChar(this.value)">
</body>
<script type="text/javascript">
function checkMultiChar(val){
var reg = /(.)\1{2}/;
alert(reg.test(val));
}
</script>
</html>