当前位置: 首页 > 图文教程 > 网络编程 > 正则表达式 > ip138中各种客户端验证js代码

正则表达式
无殇 javascript正则练习器
javascript用正则表达式把1234567890替换为abcdefghij
一个匹配形如“#100”的正则表达式
又一不错的应用-正则来查找替换字符串
[asp]中的正则表达式运用代码
asp 正则表达式检测http开头的函数
javascript下正则匹配百分比的代码
javascript下一个还原html代码的正则
JS正则表达式提取字符串中所有汉字的脚本
[asp]匹配网址的正则
[js]一个只删除所有font标签的正则函数
[原创]正则替换字符串功能
javascript 正则 判断是否是数字的脚本
[a] 1 [/a]转换为网址的UBB的正则
PHP下ereg实现匹配ip的正则
[js]用JAVASCRIPT正则表达式限制文本字节数的代码
dw(dreamweaver)正则表达式函数列表
[原创]java 正则表达式基础,实例学习资料收集大全
asp下替换非数字为空的正则
javascript利用正则快速找出两个字符串的不同字符

正则表达式 中的 ip138中各种客户端验证js代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 150 ::
收藏到网摘: n/a

包括ip验证,身份证验证,手机号码验证,电话号码,邮政编码验证,域名验证等,其实好的代码,都在应用中,大家多去扒代码吧。

复制代码 代码如下:

function checkIP()
{
var ipArray,ip,j;
ip = document.ipform.ip.value;
if(/[A-Za-z_-]/.test(ip)){
if (ip.indexOf(" ")>=0){
ip = ip.replace(/ /g,"");
document.ipform.ip.value = ip;
}
if (ip.toLowerCase().indexOf("http://")==0){
ip = ip.slice(7);
document.ipform.ip.value = ip;
}
if(!/^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(net\.cn)|(org\.cn)|(name)|(biz)|(tv)|(cn)|(mobi)|(name)|(sh)|(ac)|(io)|(tw)|(com\.tw)|(hk)|(com\.hk)|(ws)|(travel)|(us)|(tm)|(la)|(me\.uk)|(org\.uk)|(ltd\.uk)|(plc\.uk)|(in)|(eu)|(it)|(jp))$/.test(ip)){
alert("不是正确的域名");
document.ipform.ip.focus();
return false;
}
}
else{
ipArray = ip.split(".");
j = ipArray.length
if(j!=4)
{
alert("不是正确的IP");
document.ipform.ip.focus();
return false;
}
for(var i=0;i<4;i++)
{
if(ipArray[i].length==0 || ipArray[i]>255)
{
alert("不是正确的IP");
document.ipform.ip.focus();
return false;
}
}
}
}
function checkMobile(){
var sMobile = document.mobileform.mobile.value
if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(sMobile))){
alert("不是完整的11位手机号或者正确的手机号前七位");
document.mobileform.mobile.focus();
return false;
}
window.open('', 'mobilewindow', 'height=197,width=350,status=yes,toolbar=no,menubar=no,location=no')
}
function checkZip(){
var sZip = document.zipform.zip.value
if(!(/^\d{4,6}$/.test(sZip))){
alert("请输入邮政编码前4-6位");
return false;
}
window.open('','searchwindow','height=197,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes')
}
function checkZone(){
var sZone = document.zoneform.zone.value
if(!(/^0\d{2,6}$/.test(sZone))){
alert("请输入以“0”开头的3-7位区号");
return false;
}
window.open('','searchwindow','height=197,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes')
}
function checkArea2Zip(){
var sArea = document.area2zipForm.area.value
if(sArea==""){
alert("请输入地址");
document.area2zipForm.area.focus();
return false;
}
if(sArea.length<2){
alert("地址至少要有2个字");
document.area2zipForm.area.focus();
return false;
}
window.open('','searchwindow','height=197,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes')
}
function checkArea2Zone(){
var sArea = document.area2zoneForm.area.value
if(sArea==""){
alert("请输入地址");
document.area2zoneForm.area.focus();
return false;
}
if(sArea.length<2){
alert("地址至少要有2个字");
document.area2zoneForm.area.focus();
return false;
}
window.open('','searchwindow','height=197,width=400,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes')
}
function checkID(){
var sID = document.IDform.userid.value
if(!(/^\d{15}$|^\d{18}$|^\d{17}[xX]$/.test(sID))){
alert("请输入15位或18位身份证号");
document.IDform.userid.focus();
return false;
}
}
//-->
</script>