(Edit: What is Code Golf: Code Golf are challenges to solve a specific problem with the shortest amount of code by character count in whichever language you prefer. More info here on Meta StackOverflow. )
Code Golfers, here's a challenge on string operations.
Email Address Validation, but without regular expressions (or similar parsing library) of course. It's not so much about the email addresses but how short you can write the different string operations and constraints given below.
The rules are the following (yes, I know, this is not RFC compliant, but these are going to be the 5 rules for this challenge):
At least 1 character out of this group before the @:
A-Z, a-z, 0-9, . (period), _ (underscore)
@ has to exist, exactly one time
[email protected] ^
Period (.) has to exist exactly one time after the @
[email protected] ^
At least 1 only [A-Z, a-z] character between @ and the following . (period)
[email protected] ^
At least 2 only [A-Z, a-z] characters after the final . period
[email protected] ^^
Please post the method/function only, which would take a string (proposed email address) and then return a Boolean result (true/false) depending on the email address being valid (true) or invalid (false).
Samples:
[email protected] (valid/true) @w.org (invalid/false)
b@[email protected] (invalid/false) test@org (invalid/false)
test@%.org (invalid/false) s%[email protected] (invalid/false)
[email protected] (invalid/false) [email protected] (valid/true)
[email protected] (valid/true) foo@a%.com (invalid/false)
Good luck!
[code-golf]
questions, do so on meta.stackoverflow.com – Silviasilviculture[code-golf]
questions are being discussed on meta.stackexchange.com/questions/20912/so-weekly-code-golf – Silviasilviculture