标签:bool https rip www. var test log www false
一、javascript:function filter(){
this.isvalidurl = function(data){
if(/^((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/.test(data)){
return true;
}else{
return false;
}
}
this.isvalidemail = function(data){
if(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(data)){
return true;
}else{
return false;
}
}
this.isvalidtel = function(data){
if(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/.test(data)){
return true;
}else{
return false;
}
}
}
// var filter = new filter()
// var ret = filter.isvalidurl(‘https://www.baidu.com‘)
// console.log(ret)
true
[Finished in 0.3s]
二、php:
<?php
class filter{
public function isvalidurl($data){
if(preg_match(‘/((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/‘, $data)){
return true;
}else{
return false;
}
}
public function isvalidemail($data){
if(preg_match(‘/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/‘, $data)){
return true;
}else{
return false;
}
}
public function isvalidtel($data){
if(preg_match(‘/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/‘, $data)){
return true;
}else{
return false;
}
}
}
// $filter = new filter();
// $ret = $filter->isvalidurl(‘https://www.baidu.com‘);
// var_dump($ret);
bool(true)
[Finished in 0.1s]
标签:bool https rip www. var test log www false
原文地址:http://blog.51cto.com/12173069/2162625