<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>中英文匹配判断</title> </head> <body> <form action="" onsubmit="dosubmit()"> <input type="text" id="name"> <input type="submit" value="匹配"> </form> <script> function dosubmit(){ var name = document.getElementById(‘name‘).value; if(/^[0-9A-Za-z\u4E00-\u9FFF]+$/.test(name)){ alert(‘你输入的是中英文和数字‘); }else{ alert(‘你输入的不是中英文和数字‘); } if(name.match(/^[0-9A-Za-z\u4E00-\u9FFF]+$/)!=null){ //用正则替换字符串 alert(name.replace(/^(5201314)$/, ‘我爱你一生一世‘)); }else{ alert(‘你输入的不是中英文和数字‘); } return false; } </script> </body> </html>
时间: 2024-12-15 09:42:36