dousendun8411 2014-05-29 10:31
浏览 741
已采纳

属性<input type =“email”>在HTML5中无法正确验证

I have been using HTML5's new input types for easier validation. I have noticed a problem (tested on Chrome, but not sure about other browsers) that doesn't make much sense. If I was to place michael in my email field it will come up saying that it needs to be a valid email, fantastic, but when I try michael@test and don't have the extension, it validates properly.

What I would like to know is, is this a bug or done on purpose?

I would also like to point this problem out to people who use it in the future and think it works 100%.

Fortunately I run Laravel's own email check which works perfectly, but why wouldn't Chrome or anyone at the W3 Consortium not know of this problem? It could be quite a risk to rely on this 100% and thinking that people are using valid email addresses from this input type.

  • 写回答

1条回答 默认 最新

  • duan19913 2014-05-29 11:12
    关注

    michael@test is a valid email address in that it is formatted in a valid manner. A valid email address naturally does not mean that the email address is able to receive messages or that your mail daemon can even send messages to it.

    The W3C working group note on input type=email says that the match criteria is any string that matches the following regular expression:

    /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/
    

    Thus, ^_^"@666.42.99- is also considered a valid email address by that criteria, though the host part of the address is clearly invalid.

    Unfortunately, there is no other way to positively and conclusively verify the validity of an email address but a send a verification message there and ask for user action based on the content of that message.

    The HTML 5 validation is still pretty good at ensuring that you did not type your telephone number or address by accident in the email field; but any client data should always be considered possibly invalid and untrusted and rechecked at the server side anyway.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么