1 回答

TA貢獻1829條經驗 獲得超9個贊
//已發(fā)郵箱,注意查收。js部分代碼如下:
<script>
function $(id){
return document.getElementById(id)
}
function clear_msg(){
set_msg('');
}
function set_msg(msg){
$("tipmsg").innerHTML = msg;
}
function check_form(){
clear_msg();
var username = $('username').value,
password = $('password').value,
repasswd = $('repasswd').value,
sex = $('sex').value,
email = $('email').value;
if(!/^[a-zA-Z]/.test(username)){
set_msg("請輸入用戶名,并以字母開頭");
return false;
}
if(password.length == 0){
set_msg("請輸入密碼");
return false;
}
if(password!=repasswd){
set_msg("兩次密碼不一致,請修改");
return false;
}
if(sex.length == 0){
set_msg("請選擇性別");
return false;
}
if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email)){
set_msg("郵箱為空或格式不正確");
return false;
}
set_msg('<span style="color:#00ff00;">恭喜你?。。⊥ㄟ^驗證了</span>');
return false;//防止表單提交,如果后臺有接口改為return true; 就可以提交表單了
}
</script>
添加回答
舉報