正则表达式检查IP和EMAIL字符串的格式(Javascript实现)
2006-08-08 11:12
483 查看
function.js
//check the format of IP address
//Write by Ken
function checkIP(ip)
{
var re = /^((/d)|(([1-9])/d)|(1/d/d)|(2(([0-4]/d)|5([0-5]))))/.((/d)|(([1-9])/d)|(1/d/d)|(2(([0-4]/d)|5([0-5]))))/.((/d)|(([1-9])/d)|(1/d/d)|(2(([0-4]/d)|5([0-5]))))/.((/d)|(([1-9])/d)|(1/d/d)|(2(([0-4]/d)|5([0-5]))))$/;
if(re.test(ip))
return true;
else
return false;
}
//check the format of email
//Write by Ken
//Note:
//Begining by number or leter.
function checkEmail(email)
{
var re = /^((/d|[a-z]|[A-Z])(((/d|[a-z]|[A-Z]|/_){1,19})))@((((/d|[a-z]|[A-Z]){1,10})/.){1,4})(((/d|[a-z]|[A-Z])){2,10})$/;
//var re = /^((/d|[a-z]|[A-Z])|(((/d|[a-z]|[A-Z]){1,19})))@((((/d|[a-z]|[A-Z])/.){1, 4})(((/d|[a-z]|[A-Z])){2, 10}))$/;
if(re.test(email))
return true;
else
return false;
}
function onIPClick()
{
if(checkIP(form1.ip.value))
alert('true');
else
alert('false');
}
function onEmailClick()
{
if(checkEmail(form1.email.value))
alert('true');
else
alert('false');
}
test.html
<html>
<head>
<script language='javascript' src='function.js'>
</script>
</head>
<body>
<form name='form1'>
<span>
<input type='text' id='ip' name='ip' value='127.0.0.1'></input>
<input type='button' value='IP' onclick='javascript:onIPClick();'></input>
</span>
<span>
<input type='text' id='email' name='email' value='tanjianhui@163.com'></input>
<input type='button' value='EMAIL' onclick='javascript:onEmailClick();'></input>
</span>
</form>
</body>
</html>
//check the format of IP address
//Write by Ken
function checkIP(ip)
{
var re = /^((/d)|(([1-9])/d)|(1/d/d)|(2(([0-4]/d)|5([0-5]))))/.((/d)|(([1-9])/d)|(1/d/d)|(2(([0-4]/d)|5([0-5]))))/.((/d)|(([1-9])/d)|(1/d/d)|(2(([0-4]/d)|5([0-5]))))/.((/d)|(([1-9])/d)|(1/d/d)|(2(([0-4]/d)|5([0-5]))))$/;
if(re.test(ip))
return true;
else
return false;
}
//check the format of email
//Write by Ken
//Note:
//Begining by number or leter.
function checkEmail(email)
{
var re = /^((/d|[a-z]|[A-Z])(((/d|[a-z]|[A-Z]|/_){1,19})))@((((/d|[a-z]|[A-Z]){1,10})/.){1,4})(((/d|[a-z]|[A-Z])){2,10})$/;
//var re = /^((/d|[a-z]|[A-Z])|(((/d|[a-z]|[A-Z]){1,19})))@((((/d|[a-z]|[A-Z])/.){1, 4})(((/d|[a-z]|[A-Z])){2, 10}))$/;
if(re.test(email))
return true;
else
return false;
}
function onIPClick()
{
if(checkIP(form1.ip.value))
alert('true');
else
alert('false');
}
function onEmailClick()
{
if(checkEmail(form1.email.value))
alert('true');
else
alert('false');
}
test.html
<html>
<head>
<script language='javascript' src='function.js'>
</script>
</head>
<body>
<form name='form1'>
<span>
<input type='text' id='ip' name='ip' value='127.0.0.1'></input>
<input type='button' value='IP' onclick='javascript:onIPClick();'></input>
</span>
<span>
<input type='text' id='email' name='email' value='tanjianhui@163.com'></input>
<input type='button' value='EMAIL' onclick='javascript:onEmailClick();'></input>
</span>
</form>
</body>
</html>
相关文章推荐
- 正则表达式检查IP类型和EMAIL字符串的格式(Javascript实现)
- 检查是否输入字符串为正确的EMAIL格式 public String[] split(String regex)
- 使用JavaScript构建JSON格式字符串实现步骤
- JavaScript实现-检查字符串结尾-Confirm the Ending
- Javascript实现上传前对图片大小、格式的检查并预览
- 判断字符串是否是email格式 正则表达式
- 用JavaScript正则表达式实现Email验证
- Javascript 扩展Date对象,实现字符串与Date按指定格式字符串互转
- 用JavaScript正则表达式实现将字符串中小写字母转换成大写字母
- JavaScript实现-检查回文字符串-Check for Palindromes
- JavaScript检查电话格式与email格式
- Javascript日期格式化指定格式的字符串实现
- Javascript扩展String.prototype实现格式金额、格式时间、字符串连接、计算长度、是否包含、日期计算等功能
- JavaScript基于replace+正则实现ES6的字符串模版功能
- Javascript基本函数文件(去空格、Email格式判断)
- Javascript实现多行字符串
- android实现json数据的解析和把数据转换成json格式的字符串
- CSV文件格式解析器的实现:从字符串Split到FSM