javascript IP、域名、手機(jī)號碼正則表達(dá)式驗(yàn)證代碼
更新時間:2010年04月12日 12:45:35 作者:
一下代碼是腳本之家從多個網(wǎng)站整理并總結(jié)了下,常用正則表達(dá)式的驗(yàn)證代碼,可以直接使用。
這個手機(jī)號碼正則驗(yàn)證函數(shù)可以說是最新的都支持的,里面有詳細(xì)的介紹說明,不論以后增加什么號段大家都非常容易的稍微修改一下即可。
javascript 手機(jī)號碼正則表達(dá)式驗(yàn)證函數(shù)
//ip與域名驗(yàn)證函數(shù)
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;
}
}
}
}
//手機(jī)號碼驗(yàn)證函數(shù)
function checkMobile(){
var sMobile = document.mobileform.mobile.value
if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(sMobile))){
alert("不是完整的11位手機(jī)號或者正確的手機(jī)號前七位");
document.mobileform.mobile.focus();
return false;
}
}
//郵政編碼驗(yàn)證函數(shù)
function checkZip(){
var sZip = document.zipform.zip.value
if(!(/^\d{4,6}$/.test(sZip))){
alert("請輸入郵政編碼前4-6位");
return false;
}
}
//區(qū)號驗(yàn)證
function checkZone(){
var sZone = document.zoneform.zone.value
if(!(/^0\d{2,6}$/.test(sZone))){
alert("請輸入以“0”開頭的3-7位區(qū)號");
return false;
}
}
//身份證驗(yàn)證
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;
}
javascript 手機(jī)號碼正則表達(dá)式驗(yàn)證函數(shù)
復(fù)制代碼 代碼如下:
//ip與域名驗(yàn)證函數(shù)
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;
}
}
}
}
//手機(jī)號碼驗(yàn)證函數(shù)
function checkMobile(){
var sMobile = document.mobileform.mobile.value
if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(sMobile))){
alert("不是完整的11位手機(jī)號或者正確的手機(jī)號前七位");
document.mobileform.mobile.focus();
return false;
}
}
//郵政編碼驗(yàn)證函數(shù)
function checkZip(){
var sZip = document.zipform.zip.value
if(!(/^\d{4,6}$/.test(sZip))){
alert("請輸入郵政編碼前4-6位");
return false;
}
}
//區(qū)號驗(yàn)證
function checkZone(){
var sZone = document.zoneform.zone.value
if(!(/^0\d{2,6}$/.test(sZone))){
alert("請輸入以“0”開頭的3-7位區(qū)號");
return false;
}
}
//身份證驗(yàn)證
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;
}
相關(guān)文章
正則表達(dá)式的神奇世界之表達(dá)、匹配和提取全解析
這篇文章主要給大家介紹了關(guān)于正則表達(dá)式的神奇世界之表達(dá)、匹配和提取的相關(guān)資料,正則表達(dá)式是由一些特定的字符組成,代表一個規(guī)則,可以用來檢驗(yàn)數(shù)據(jù)格式是否合法,也可以在一段文本中查找滿足要求的內(nèi)容,需要的朋友可以參考下2024-02-02Python使用正則表達(dá)式去除(過濾)HTML標(biāo)簽提取文字功能
這篇文章主要介紹了Python使用正則表達(dá)式去除(過濾)HTML標(biāo)簽提取文字,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值 ,需要的朋友可以參考下2019-07-07