Validate email address textbox using JavaScript

前端 未结 10 847
一个人的身影
一个人的身影 2020-12-02 17:03

I have a requirement to validate an email address entered when a user comes out from the textbox.
I have googled for this but I got form validation JScript; I don\'t wa

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 17:53

    Are you also validating server-side? This is very important.

    Using regular expressions for e-mail isn't considered best practice since it's almost impossible to properly encapsulate all of the standards surrounding email. If you do have to use regular expressions I'll usually go down the route of something like:

    ^.+@.+$
    

    which basically checks you have a value that contains an @. You would then back that up with verification by sending an e-mail to that address.

    Any other kind of regex means you risk turning down completely valid e-mail addresses, other than that I agree with the answer provided by @Ben.

提交回复
热议问题