<!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>