87,990
社区成员
发帖
与我相关
我的任务
分享
//-------------------1---------------
var data = [
"12324542152",
"A23AD3UE78Q9P3"
];
var reg1 = /^[A-Z0-9]{6,}$/;
for (var i = 0; i < data.length; i++) {
if (reg1.test(data[i])) {
if (!/[A-Z]/.test(data[i]) || !/[0-9]/.test(data[i])) {
alert(data[i] + " " + "error .");
}
else
alert(data[i] + " " + "success .");
}
else
alert(data[i] + " " + "error .");
}
//-------------------2---------------
for (var i = 0; i < data.length; i++) {
if (reg1.test(data[i])) {
if (!/[A-Z]/.test(data[i]) || !/[0-9]/.test(data[i])) {
alert(data[i] + " " + "error .");
}
else {
if (data[i].match(/[0-9]/g).length >= 5) {
alert(data[i]+" success and no. length larger than 5");
}
else {
alert(data[i]+" success and no. length small than 5");
}
}
}
else
alert(data[i] + " " + "error .");
}
//--------------1-----------------
<script type="text/javascript">
var data = [
"12324542152",
"A23AD3UE78Q9P3"
];
var reg1 = /^[A-Z0-9]{6,}$/;
for (var i = 0; i < data.length; i++) {
if (reg1.test(data[i])) {
if (!/[A-Z]/.test(data[i]) || !/[0-9]/.test(data[i])) {
alert(data[i] + " " + "error .");
}
else
alert(data[i] + " " + "success .");
}
else
alert(data[i] + " " + "success .");
}
</script>
<!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 type="text" id="te" />
<input type="button" value="text" id="btn" />
<script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('te').value,count = 0;
if(value.length >= 6){
if(value == value.toUpperCase()){
for(var i = 0; i < value.length; i++){
if((+value.charAt(i)) > 0){
count++;
}
}
if(count > 5){
alert('输入正确');
}
}
}else{
alert('输入字符少于6个');
}
};
</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 type="text" id="te" />
<input type="button" value="text" id="btn" />
<script>
document.getElementById('btn').onclick = function(){
var value = document.getElementById('te').value,count = 0;
if(value.length >= 6){
if(value == value.toUpperCase()){
for(var i = 0; i < value.length; i++){
if((+value.charAt(i)) > 0){
count++;
}
}
if(count == 5){
alert('输入正确');
}
}
}else{
alert('输入字符少于6个');
}
};
</script>
</body>
</html>