var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if(reg.test(card) === false)
{
alert("身份证输入不合法");
return false;
}
<script>function $(e){return document.getElementById(e);}function go(){var reg=/^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]
{16}([0-9]|[xX])$/;if(reg.test($("check").value)){alert("ok");}else{alert("no");}}</script></head><body><input
id="check" type="text" οnchange="go()" /></body>