正则Js
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script>
var reg = /\d{5}/g;
var msg = ‘中国移动:10086,中国联通:10010,中国电信:10000‘;
//alert(reg.test(msg));//test方法判断的有没有匹配上,返回的bool值
//alert(reg.exec(msg));//在正则表达式后面加一个g
//循环取匹配的值
while ((result=reg.exec(msg)) != null) {
alert(result);
}
onload = function () {
//var reg = /\w+((-w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+/;
//document.getElementById(‘txt‘).onblur = function () {
// //document.getElementById(‘txt‘).value//拿到文本框的值
// if (!reg.test(this.value)) {
// alert(‘不是邮箱‘);
// };
//};
//var msg = ‘14333338888,15844440000,18515880000‘;
//var result= msg.replace(/(\d{3})(\d{4})(\d{4})/g, ‘$1****$3‘);
//alert(result);
var msg = ‘ 123 ‘;
function trimString(msg) {
return msg.replace(/^\s+/, ‘‘).replace(/\s+$/, ‘‘);
}
var res = trimString(msg);
alert(‘==‘+res+‘==‘);
};
</script>
</head>
<body>
邮箱<input type="text" name="name" value=" " id="txt"/>
</body>
</html>
==================================================
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script>
onload = function () {
document.getElementById(‘txt‘).onkeyup = function () {
var tds = document.getElementById(‘tb‘).getElementsByTagName(‘td‘);
for (var i = 0; i < tds.length; i++) {
tds[i].style.backgroundColor = ‘‘;
}
var num = checkPwd(this.value);
if (this.value.length > 0) {
if (num == 3) {
tds[0].style.backgroundColor = ‘blue‘;
tds[1].style.backgroundColor = ‘blue‘;
tds[2].style.backgroundColor = ‘blue‘;
} if (num == 2) {
tds[0].style.backgroundColor = ‘yellow‘;
tds[1].style.backgroundColor = ‘yellow‘;
} if (num <= 1) {
tds[0].style.backgroundColor = ‘red‘;
}
}
};
};
function checkPwd(msg) {
var lvl = 0;
if (msg.match(/[0-9]/)) {
lvl++;
}
if (msg.match(/[a-zA-Z]/)) {
lvl++;
}
if (msg.match(/[^a-zA-Z0-9]/)) {
lvl++;
}
if (msg.length < 6) {
lvl--;
}
return lvl;
}
</script>
</head>
<body>
密码:<input type="text" name="name" value=" " id="txt" /><br />
<table id="tb" border="1" style="width: 300px; height: 30px; font-size: 25px; text-align: center;">
<tr>
<td>
弱
</td>
<td>
中
</td>
<td>
强
</td>
</tr>
</table>
</body>
</html>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。