<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div>
<input type="text" placeholder="隻能輸入數字" oninput="if(!(/^[0-9]*$/.test(value))){value = ''}" />
<!-- 利用oninput監聽輸入 如果值不是正則比對的數字 就置空 -->
<br>
<input type="text" placeholder="數字或英文或數字加英文"
oninput="if(!( (/^[0-9]*$/.test(value)) || (/^[A-Za-z]+$/.test(value)) || (/^[A-Za-z0-9]+$/.test(value)) )){value = ''}" />
</div>
</body>
</html>