例子:
验证邮箱输入的格式是否正确。
<script language="javascript" type="text/javascript" > /** * Check email format */ function emailCheck(obj, labelName) { var objName = eval("document.all."+obj); var pattern = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; if (!pattern.test(objName.value)) { alert("请输入正确的邮箱地址。"); objName.focus(); return false; } return true; } </script> email:<input type="text" id="email" name="email" maxlength="30" onblur="return emailCheck('email', 'email')" style="text-align: left; width:300px;" />