simonrl
  • simonrl
  • 51% (Neutral)
  • Administration Topic Starter
9 years ago
Completely off topic.

Is anybody on here a guru with RegEx (regular expressions)?

I'm having trouble with the one that validates the format of an email address (for the login on this web site). And I can't get my head around fixing the issue.
my orders are to sit here and watch the world go by
BertyBasset
9 years ago
We use the following - written by a colleague, so can't comment on any false positives etc.

^[^@ ]+@[^.@ ]+(\.[^.@ ]+)+$

Robin
simonrl
  • simonrl
  • 51% (Neutral)
  • Administration Topic Starter
9 years ago
Thank you 🙂 I'm using:

^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"

Which seems inordinately long in comparison. But so far I've had two complaints:

1, It didn't let through a + symbol in an email address prefix (you know who you are!)

2, It didn't let through a CompuServe email address in the format [email protected]

Looking at your example it looks as if it would pass those two. I'll give it a go...
my orders are to sit here and watch the world go by
simonrl
  • simonrl
  • 51% (Neutral)
  • Administration Topic Starter
9 years ago
That seems to work very nicely. Thank you. :flowers:
my orders are to sit here and watch the world go by
sinker
  • sinker
  • 50.2% (Neutral)
  • Newbie
9 years ago
"SimonRL" wrote:



^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"





:blink:
Yma O Hyd....
JohnnearCfon
9 years ago
"sinker" wrote:

"SimonRL" wrote:



^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"





:blink:



Is that a new mine somewhere? :confused::confused::confused:

Let me guess, pot noodle?
skimble
9 years ago
"BertyBasset" wrote:

We use the following - written by a colleague, so can't comment on any false positives etc.

^[^@ ]+@[^.@ ]+(\.[^.@ ]+)+$


&@!.* seems to be an acceptable address according to the above (or am I misreading it?).
Should the conditions for the domain name be tighter?
simonrl
  • simonrl
  • 51% (Neutral)
  • Administration Topic Starter
9 years ago
"skimble" wrote:

"BertyBasset" wrote:

We use the following - written by a colleague, so can't comment on any false positives etc.

^[^@ ]+@[^.@ ]+(\.[^.@ ]+)+$


&@!.* seems to be an acceptable address according to the above (or am I misreading it?).
Should the conditions for the domain name be tighter?



You're correct, it does let that through 😢
my orders are to sit here and watch the world go by
rufenig
9 years ago
My brain hurts. :surrender:
ttxela
  • ttxela
  • 50.2% (Neutral)
  • Newbie
9 years ago
Looks like the sort of thing characters in the Beano used to say when they dropped anvils on their foot.
davel
  • davel
  • 50.2% (Neutral)
  • Newbie
9 years ago
"skimble" wrote:

"BertyBasset" wrote:

We use the following - written by a colleague, so can't comment on any false positives etc.

^[^@ ]+@[^.@ ]+(\.[^.@ ]+)+$


&@!.* seems to be an acceptable address according to the above (or am I misreading it?).
Should the conditions for the domain name be tighter?



It's complicated ... :(

See RFC 5321 and RFC 5322, and extensions like RFC 6531 etc. for more than you really want to know about email addresses. :confused:

The simple case is that domain names should (generally) contain only the ASCII letters 'a' to 'z' (in a case-insensitive manner), the digits '0' to '9', and the hyphen ('-'), so in the example that skimble gives, the domain name !.* is not valid. (This simple specification does not allow for non-ASCII characters in domain names or non-latin scripts, both of which are permissible). Also, there are length limitations on the domain names parts and the overall length.

A more strict regex might be:

^[^@ ]+@[0-9A-Za-Z\-]{1,62}(\.[0-9A-Za-Z\-]{1,62})+$

In addition, the hostname (including dots) should not be more than 254 characters.

However, the above regex does not validate internationalized domain names such as üñîçøðé@üñîçøðé.com, literal IPv6 addresses such as user@[IPv6:2001:db8::1] or those in non-latin scripts (I leave those as an exercise for the reader 🙂 )

Dave
Willy Eckerslyke
9 years ago
One should, of course, remember that the reverse diagonal should be avoided unless preceded by a 3-character cyclical. Failure to observe this simple rule brings Moreton’s convention into play and there's no knowing where you'll end up!
"The true crimefighter always carries everything he needs in his utility belt, Robin"
skimble
9 years ago
"Willy Eckerslyke" wrote:

One should, of course, remember that the reverse diagonal should be avoided unless preceded by a 3-character cyclical. Failure to observe this simple rule brings Moreton’s convention into play and there's no knowing where you'll end up!


Mornington Crescent!
Willy Eckerslyke
9 years ago
"skimble" wrote:

Mornington Crescent!


Blimey, that was quick! :thumbsup:
"The true crimefighter always carries everything he needs in his utility belt, Robin"
exspelio
9 years ago
"rufenig" wrote:

My brain hurts. :surrender:



Mine too --- AAARGH---:o:o
Always remember, nature is in charge, get it wrong and it is you who suffers!.
BertyBasset
9 years ago
Quote:

Mine too



Repetition! - oops, wrong game.
Digit
  • Digit
  • 50.2% (Neutral)
  • Newbie
9 years ago
"JohnnearCfon" wrote:

"sinker" wrote:

"SimonRL" wrote:



^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"




:blink:




Is that a new mine somewhere? :confused::confused::confused:

Let me guess, pot noodle?



Actually its the Midnight Oil Well.
~~~ The future is not what it used to be ~~~
ebgb
  • ebgb
  • 50.2% (Neutral)
  • Newbie
9 years ago
if you come over from the dark side I've a few neat php routines I've put together over the years that are pretty robust for fishing through strings in an email address

simonrl
  • simonrl
  • 51% (Neutral)
  • Administration Topic Starter
9 years ago
"ebgb" wrote:

if you come over from the dark side I've a few neat php routines I've put together over the years that are pretty robust for fishing through strings in an email address



Recoding the entire site in PHP would be a bit of an undertaking :lol:
my orders are to sit here and watch the world go by
TwllMawr
9 years ago
426c6f6f647920736f66747761726520656e67696e65657273203a2d29

Disclaimer: Mine exploring can be quite dangerous, but then again it can be alright, it all depends on the weather. Please read the proper disclaimer.
© 2005 to 2023 AditNow.co.uk

Dedicated to the memory of Freda Lowe, who believed this was worth saving...