天天看點

Javascript 驗證輸入表單的正确性

<html>

??? <head>

??? ??? <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

??? ??? <title>浣跨??avaScript楠?璇?杈??ヨ〃????姝g‘??</title>??? ???

??? ??? <script type="text/javascript">

??? ??? ??? function CheckForm(objForm)

??? ??? ??? {

??? ??? ??? ??? var rNums=/[0-9]{1}/;

??? ??? ??? ??? if (!rNums.test(objForm.num.value))

??? ??? ??? ??? {

??? ??? ??? ??? ??? ??? window.alert('璇瘋??ヤ?涓??闆??!');

??? ??? ??? ??? ??? ??? objForm.num.focus();

??? ??? ??? ??? ??? ??? return false;

??? ??? ??? ??? }

??? ??? ??? ??? if (objForm.siteurl.value !='www.dreamdu.com')

??? ??? ??? ??? {

??? ??? ??? ??? ??? ??? window.alert('璇瘋??ョ?懼害??缃???!');

??? ??? ??? ??? ??? ??? objForm.siteurl.focus();

??? ??? ??? ??? ??? ??? return false;

??? ??? ??? ??? }

??? ??? ??? ??? return true;

??? ??? ??? }

??? ??? </Script>

??? </head>

??? <body>

??? ??? <form name="form1" method="post" action="/dreamdu.php">

??? ??? 璇瘋??ヤ?涓??闆??:<input name="num" type="text" value="" /><br />

??? ??? 璇瘋??ョ?懼害??缃???:<input name="siteurl" type="text" value="" />

??? ??? <input type="submit" name="submit" onClick="javaScript:return CheckForm(form1)" />

??? ??? </form>

??? ???

??? </body>

</html>

繼續閱讀