Search code examples
phpjqueryemail-validationmaxlength

Is it bad to limit length when creating email validation code?


I am learning jQuery and PHP to create my own form validation. I have read several tutorials but I do not see any consideration or notation in regards to capping the maximum length? I did see minimum length requirement suggestions but I wanted to know if this was a best practice to limit the maximum allowed characters.

Does this sound good?

  • Email address = 25 characters
  • Name = 20 characters
  • Message = 200 characters with a notation that there is a max.

Solution

  • RFC 3696 says that the maximum total length for an email address is 320 characters ("local part": 64 + "@" symbol: 1 + "domain part": 255 = 320). It's very rare that you'll encounter an address this long, but you should support them nevertheless.

    Source: https://www.rfc-editor.org/rfc/rfc3696 (section 3: Restrictions on email addresses, last paragraph)