Email regex with character limit (without lookahead)
I have a regex: "\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}\b" for validating email addresses within ASP.NET.
I would like to be able to limit the overall number o开发者_开发知识库f characters between 6 & 100 characters. I'm coding for IE 6, so how can this be done without using a lookahead?
Many thanks
Why not just check the length separately, instead of trying to shoehorn it into the regex?
Give this a spin:
This requires the username to be between 6 and 600 characters. Without knowing how long the domain may be, I don't think you're going to be able to limit it effectively without a lookahead (or behind). The only possible workaround I can think of would be to set arbitrary limits on each: say 300 for the username, and 300 for the domain.
^(#?[_a-zA-Z0-9+-](\.?[_a-zA-Z0-9+-]{5,599})*)@([a-zA-Z0-9]+(-(?!-)|[a-zA-Z0-9\.])*?[a-zA-Z0-9]+\.([0-9]{1,3}|[a-zA-Z]{2,3}|(aero|arpa|asia|coop|info|jobs|mobi|museum|name|travel)))$
精彩评论