05 April 2015

Code thiết kế form ĐĂNG KÝ THÔNG TIN - PHẦN 2: Dựng kịch bản

Ở phần 1, mình đã thiết kế xong giao diện form nói trên, và phần này mình sẽ dựng kịch bản bằng javascript theo yêu cầu nói trên.
Code này chỉ mang tính chất tham khảo và dành cho người mới học lập trình web.

function KiemTra(){
 taikhoan = document.xuly.taikhoan.value;
 pass = document.xuly.pass.value;
 lapmatkhau = document.xuly.lapmatkhau.value;
 email = document.xuly.email.value; 
 var emailReg =/[\w.]*[\w]@[\w][\w.]*\.[\w][\w]*/;
    var regex = new RegExp(emailReg);
 hoten = document.xuly.hoten.value;
 if(taikhoan.length < 8){
  alert("Tai khoan it nhat 8 ky tu.");
  document.xuly.taikhoan.focus();
  }
 else if(pass.length == 0){
  alert("Mat khau khong duoc rong.");
  document.xuly.pass.focus();
  }
 else if(lapmatkhau != pass){
  alert("Mat khau khong khop.");
  document.xuly.lapmatkhau.focus();
 }
 else if(!regex.test(email)){
  alert("Email khong hop le.");
  document.xuly.email.focus();
 }
 else if(hoten.length == 0){
  alert("Ho ten khong duoc rong.");
  document.xuly.hoten.focus();  
 }
 else
  alert("du lieu hop le");  
 }
NGUYỄN THIÊN TỨ
Nguồn: w3refer.com

Related Posts

Code thiết kế form ĐĂNG KÝ THÔNG TIN - PHẦN 2: Dựng kịch bản
4/ 5
Oleh