正则匹配(URL、电话、手机、邮箱)

2018-06-24 00:02:02来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正则验证</title>
</head>
<body>
<input type="text" name="" id="text">
<input type="button" name="" id="btn" value="点击">
<span></span>
</body>
<script type="text/javascript">
var text = document.getElementById('text');
var btn = document.getElementById('btn');

//1、url示例:
//https://www.baidu.com/s?wd=%E5%88%98%E5%BE%B7%E5%8D%8E&rsv_spt=1&rsv_iqid=0x9601edc200017402&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&rqlang=cn&tn=baiduhome_pg&rsv_enter=1&oq=javascript%2520%25E9%259A%25BE%25E9%25A2%2598&inputT=1256&rsv_t=7da5GmMhTie86h8qaOiaV047P9TkJunMjrkmK%2BNLA%2FuJs3bMG%2Bj52w%2F6IxHge5MB%2B%2B%2Fw&rsv_pq=c270d50b00019cae&rsv_sug3=21&rsv_sug1=19&rsv_sug7=100&rsv_sug2=0&rsv_sug4=1818
//2、电话示例:
//13800138000
//+ 8610 - 59926666
//+ (1)533- 222 - 334
//010 - 59926666
//037132376865
//3、电子邮件示例:
//Handsome.W@abc.com
//_hello_world@163.com
//345@mail.some_domain_name.com.uk

// var regexp=/^([0-9a-zA-Z_.-])+@([0-9a-zA-Z_-])+(\.([a-zA-Z_-])+)+$/;//邮箱
// var regexp=/(https?.*?\.(:?cn\b|com\b|net\b|org\b|gov\b)(?!\.))/;//URL
// var regexp=/\+?\d{3,4}-?\d{7,8}/; // 010-59926666 8610-59926666 037132376865
// var regexp =/\+\(\d\)(\d{3}-){2}\d{3}/;//+(1)533-222-334
// var regexp=/(1[34578]\d{9})|(\+?\d{3,4}-?\d{7,8})|(\+\(\d\)(\d{3}-){2}\d{3})/;//电话号码 13800138000 010-59926666 8610-59926666 037132376865 +(1)533-222-334
var regexp=/(([0-9a-zA-Z_.-])+@([0-9a-zA-Z_-])+(\.([a-zA-Z_-])+)+)|((https?.*?\.(:?cn\b|com\b|net\b|org\b|gov\b)(?!\.)))|(1[34578]\d{9})|(\+?\d{3,4}-?\d{7,8})|(\+\(\d\)(\d{3}-){2}\d{3})/;

btn.onclick = function(){
if(regexp.test(text.value)){
alert('验证通过');
text.value="";
}else{
alert('验证没通过');
}
}
</script>
</html>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:字符串转base64,base64转字符串

下一篇:vue小组件练习之文字居中对齐组件