本文介绍了javascript valiadtion问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了2页登录和注册。在注册页面上,我正在使用javascript进行验证。



 <   head       runat   =  server  >  
< script type = text / javascript >
函数Validateform(){
var msg =;



if(document.getElementById(txtfirst)。valueOf ==){
msg + =输入Firstname \ n;
}
else {
var ex = / ^ [a-zA-Z] /;
if(ex.test(document.getElementById(txtfirst)。valueOf == false)){
msg + =请仅输入名字中的字符\ n;
}
}
< / script >
if(msg ==){
return true;
}
else {
alert(msg);
返回false;
}

< td colspan = 2 >
< asp:按钮 ID = signupbtn runat = server 文本 = 注册 onclick = signupbtn_Click OnClientClick = 返回Validateform(); = 按钮 / >
< ; asp:按钮 ID = cancelbtn runat = server 文本 = 取消 onclick = cancelbtn_Click = 按钮 / >
< / td >





但它无法正常工作。问题是,当我输入正确的数据时,它仍然给我验证错误按摩。并且非空场的验证根本不起作用。

请帮忙。它很紧急。谢谢你提前

解决方案


使用

  if  document  .getElementById(  txtfirst)。value ==   





而不是



  if  document  .getElementById(  txtfirst)。valueOf ==   


I have created 2pages login and signup. On signup page i am doing validations using javascript.

<head  runat="server">
    <script type="text/javascript">
        function Validateform() {
            var msg = "";



            if (document.getElementById("txtfirst").valueOf == "") {
                msg += "Enter Firstname\n";
            }
            else {
                var ex = /^[a-zA-Z]/;
                if (ex.test(document.getElementById("txtfirst").valueOf == false)) {
                    msg += "please enter only characters in first name\n";
                }
            }
</script>
 if (msg == "") {
                return true;
            }
            else {
                alert(msg);
                return false;
            }

 <td colspan="2">
               <asp:Button ID="signupbtn" runat="server" Text="Sign Up" onclick="signupbtn_Click" OnClientClick="return Validateform();" Class="button" />
                <asp:Button ID="cancelbtn" runat="server" Text="Cancel" onclick="cancelbtn_Click" Class="button" />
        </td>



But it is not working properly. The problem is that when i enter correct data it is still giving me validation error massages. and also validation for non empty field is not at all working.
please help. Its urgent.Thank you in advance

解决方案



这篇关于javascript valiadtion问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:20