News for hackers. Stuff that matters.
Re:Ruby's Email Address Regexp by mkdirp on Tuesday January 04, 2022 @09:59PM (#29804471)
Never mind the regex, `email.indexOf("@") > 2` does the trick and faster if you happen to need to check many emails. All websites these days require verification of emails (regardless of whether or not it's necessary), and if that's not enough validation, I don't know what is!
Re:Ruby's Email Address Regexp by rhinoceraptor on Tuesday January 04, 2022 @10:38PM (#29804811)
I would use `email.includes('@')`, it only needs to be polyfilled for IE since it's in every modern browser JS engine.
Re:Ruby's Email Address Regexp by gumby on Tuesday January 04, 2022 @10:46PM (#29804865)
Why 2? Greater than 0, sure.
Re:Ruby's Email Address Regexp by zamadatix on Tuesday January 04, 2022 @11:00PM (#29804964)
The index of the first character is 0 and an email must have a local part so that means the index of "@" has to be at least 1. My guess is OP also forgot the index of the first character is 0 instead of 1 resulting in 1+1=2 (that or they meant >=).

Off by one errors are about half of working with arrays.

Re:Ruby's Email Address Regexp by zarzavat on Wednesday January 05, 2022 @02:35AM (#29806209)
This is actually an uncommon example of an off-by-two error as they used strictly greater than 2.

  a@domain   fail
  ab@domain  fail
  abc@domain ok
Re:Ruby's Email Address Regexp by lostcolony on Tuesday January 04, 2022 @10:55PM (#29804932)
Yeah...I have an email address I use a lot, "me@(domain)". It's perfectly valid, despite indexOf("@") == 2.
Re:Ruby's Email Address Regexp by mkdirp on Wednesday January 05, 2022 @06:50AM (#29807878)
Heh, I actually meant `>=`. But as others have pointed out, that still excludes 2 letter users. Really it should be `>= 0`.
Re:Ruby's Email Address Regexp by lostcolony on Wednesday January 05, 2022 @11:42AM (#29811265)
> 0 I would think, no? Can an email address be '@domain', no preface?