常用正則表達式

去掉了全角,特殊字符的正則表達式:this.value=this.value.replace(/[^a-zA-Z0-9-, ()/u4E00-/u9FA5]*$/,'')

 

 

 

//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;
}
}
//郵政編碼驗證函數
function checkZip(){
var sZip = document.zipform.zip.value
if(!(/^/d{4,6}$/.test(sZip))){
alert("請輸入郵政編碼前4-6位");
return false;
}
}
//區號驗證
function checkZone(){
var sZone = document.zoneform.zone.value
if(!(/^0/d{2,6}$/.test(sZone))){
alert("請輸入以“0”開頭的3-7位區號");
return false;
}
}
//身份證驗證
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;
}
詳細出處參考:http://www.jb51.net/article/23021.htm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章