-3

可能重复:
使用正则表达式验证电子邮件地址

我希望有一个用于电子邮件验证的 reg ex,它应该支持以下内容 -

  • 大写和小写英文字母(a-z、A-Z)
    • 数字 0 到 9
    • 字符 !#$%&'*+-/=?^_`{|}~
    • 特点 。(点、句号、句号),前提是它不是第一个或最后一个字符,并且它不连续出现两次或多次(例如 abhi..shekk@example.com)。
    • 允许使用特殊字符,但有以下限制:
      • 空格和 "(),:;<>@[]

我需要在提交表单时使用 javascript 方法验证电子邮件 ID 吗?

谢谢,

阿布舍克

4

1 回答 1

1

First, I don't understand the last item of the list of requirements of Regular Expression:

  • Special characters are allowed with restrictions including:
    • Space and "(),:;<>@[]

The second, you should ALWAYS validate regular expression on server side. Because unless you are doing so, validating has no sense - client may use his own tool to send request to server. client validation will be good for warning user about mistakes prior to submission of the form. And yes, you should validate all fields on form submission. You could run any JavaScript function. <form> tag has event onSubmit() for that.

于 2012-07-16T12:07:04.550 回答