如何检查文本验证不是电子邮件? [英] How to check validation for a text is not an email?
问题描述
我有一个用户输入为text,但人们坚持要输入他们的电子邮件地址。
I have an user input as "text", however people insist on typing their email addresses to that input.
有没有办法阻止人们输入他们的电子邮件用HTML5或任何其他方式的地址?
Is there a way to prevent people typing their email address with HTML5 or any other way?
此代码检查输入是否是电子邮件,我需要相反的加输入类型文本。
This code checks if the input is an email, I need the opposite plus input type text.
此外,如果可能,我必须设置自定义验证消息。
Also I have to Set custom validation message if possible.
<form action="/action_page.php">
E-mail: <input type="email" name="email" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$">
<input type="submit">
</form>
这就是我将如何将它与自定义验证消息一起使用
This is how I will use it with custom validation message
<input type="text" name="username" id="username" pattern="THIS IS THE PATTERN I AM LOOKING FOR" required placeholder="Enter user name"
oninvalid="this.setCustomValidity('Do not type an email address here')"
oninput="this.setCustomValidity('')" />
推荐答案
这是使用HTML5输入模式的一种方法。
Here's one way to do it, using HTML5's input patterns.
<input type="text"
name="username"
pattern="^[^@]+$">
这说如果有,请不要让表单提交@
文本中的任何地方。
That says "Don't let the form submit if there is an @
anywhere in the text."
请参阅 http://html5pattern.com/ 如果您想测试一下。
See http://html5pattern.com/ if you'd like to test it out.
这篇关于如何检查文本验证不是电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!