0

I am sending an email address value to a third party service. I have following regex to validate email addresses:

`^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})$`

but suppose someone tries to send as email address:

'WQWQQWWQQWQWWQWQQWW@WEOIWEOIEWOIEWIOWEIOEWIOEWPIOWEPOIWEPEWIOPIOWEOIWEOIEWIOWIOEWIOPEWIOPWIOEPIOWPEIOEWOIEWOIPIOEW.COM' 

this address is valid and then I get error in response object from the service. My question is, what can be the possible maximum character limit for the domain part?

Simon
  • 6,062
  • 13
  • 60
  • 97
Huma Ali
  • 1,759
  • 7
  • 40
  • 66
  • On a slightly different topic: Don't use Regex to validate email addresses. Just send an the mail - [Reasons here](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address?rq=1) – Manfred Radlwimmer Sep 01 '16 at 09:50

1 Answers1

4

A full domain name can have no more than 253 characters in its textual representation.

https://en.wikipedia.org/wiki/Domain_Name_System

A label may contain zero to 63 characters. The null label, of length zero, is reserved for the root zone. The full domain name may not exceed the length of 253 characters in its textual representation. In the internal binary representation of the DNS the maximum length requires 255 octets of storage, since it also stores the length of the name.

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
js441
  • 1,134
  • 8
  • 16
  • This is incorrect. [**RFC1034**](https://tools.ietf.org/html/rfc1034): To simplify implementations, the total number of octets that represent a domain name (i.e., the sum of all label octets and label lengths) is limited to 255. – HoldOffHunger Feb 13 '21 at 17:45