【關於JavaScript】常見表單使用者名稱、密碼不可為空

來源:互聯網
上載者:User

標籤:

在論壇等系統的使用者註冊功能中,如果使用者忘記填寫必填資訊,如使用者名稱、密碼等,瀏覽器會彈出警告框,提示使用者當前有未填資訊。

這個典型的應用就是通過JavaScript實現的。是一個簡單的使用者註冊頁面:

按要求使用者必須輸入使用者名稱、密碼和確認密碼,而且兩次輸入的密碼必須相同,否則,系統會提示錯誤。

當使用者沒有輸入使用者名稱就提交註冊時,系統會彈出如所示的警告視窗,強制使用者必須輸入使用者名稱。

 

簡單的做法:

 1 <script language="JavaScript"> 2 function check(){ 3 if(document.form1.username.value==""){ 4 alert("使用者名稱不可為空!"); 5 document.form1.username.value.focus(); 6 return false; 7 } 8 if(document.form1.password.value==""){ 9 alert("密碼不可為空!");10 document.form1.password.value.focus();11 return false;12 }13 if(document.form1.password.value.length<6)14 {15     alert("密碼長度不能少於6位");16     document.form1.password.value.focus();17     return false;18 }19 else20 if(document.form1.repassword.value!=document.form1.password.value){21 alert("兩次輸入的密碼不一致!");22 document.form1.repassword.focus();23 return false;24 }}25 </script>

 

【關於JavaScript】常見表單使用者名稱、密碼不可為空

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.