我已经在我的项目中验证了电子邮件,但它不允许我输入一个字母 [英] I have done validating email in my project, but it is not allowing me to enter a single letter

查看:117
本文介绍了我已经在我的项目中验证了电子邮件,但它不允许我输入一个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要验证我的电子邮件ID并且我已完成以下代码,它正在验证但不允许甚至没有我已包含在我的函数中的单个字符



我尝试过:



Hi I need to validate my email id and I have done the below code,it is validating but not allowing not even a single character which I have included in my function

What I have tried:

<pre>function validateEmail(e) {
                    var mail = document.getElementById("<%=TxtEmail.ClientID%>");
                    var re = /^w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})*$/;
                    if (e.value.match(re)) {
                        return true;
                    }
                    else {
                        alert("email not valid")
                        return false;
                    } 
                }

<tr>
                    <td style="width: 362px">Email
                    </td>
                    <td>
                        <asp:TextBox ID="TxtEmail" onkeypress="validateEmail(this)" runat="server" Height="21px" Width="122px" />
                    </td>

                </tr>

推荐答案

/;
if (e.value.match(re)){
return < span class =code-keyword> true ;
}
else {
alert( 电子邮件无效
return false ;
}
}
/; if (e.value.match(re)) { return true; } else { alert("email not valid") return false; } }

<tr>
                    <td style="width: 362px">Email
                    </td>
                    <td>
                        <asp:TextBox ID="TxtEmail" onkeypress="validateEmail(this)" runat="server" Height="21px" Width="122px" />
                    </td>

                </tr>


每次按键时都会尝试验证地址,但地址有效只有当你完成输入时才会这样。

你只需要在最后验证。您需要使用 oninput 之类的事件,请参阅 textbox 文档中哪些事件可用。

HTML DOM事件对象 [ ^ ]
You try to validate the address every time you press a key, but the address can be valid only when you finished typing.
You need to validate only at the end. You need to use an event like oninput, see in textbox documentation which event is available.
HTML DOM Event Object[^]


这篇关于我已经在我的项目中验证了电子邮件,但它不允许我输入一个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆