<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>邮箱匹配</title> </head> <body> 手机号:<input type="text" id="texts"><br \> 邮箱:<input type="text" id="shouji" onblur=‘func(this)‘> <script type="text/javascript"> //获取输入的手机号 var texts = document.getElementById(‘texts‘); //获取输入的邮箱 var shouji1 = document.getElementById(‘shouji‘); //手机号输入框失去焦点 texts.onblur = function(){ var tv = this.value; var reg = /^1[345789]\d{9}$/; if (reg.test(tv)){ alert(‘Yes‘) }else{ alert(‘No‘) } } //console.log(str); //邮箱输入框失去焦点 function func(obj){ var tv = obj.value; var reg = /^\w+\@+[0-9a-zA-Z]+\.(com|com.cn|edu|hk|cn|net)$/; if(reg.test(tv)){ alert(‘邮箱格式正确‘); }else{ alert(‘邮箱格式不正确‘) } } var as = ‘<a href="http://www.sina.com.cn">sina</a>‘ var reg = /<a href="(.*)">(.*)<\/a>/; var str = reg.exec(as); console.log(str); </script> </body> </html>
原文地址:https://www.cnblogs.com/Fantinai/p/8119675.html
时间: 2024-10-07 22:18:57