I am trying to validate email in SQL using RegEX to achieve below criteria.
Create a query (use the operator LIKE) that searches for all the Email Addresses that contain:
- Only one symbol “@”
- At least one symbol “.”
- If there is only one “.” symbol it should be after the symbol “@” (and not before it)
- At least 6 characters
- The symbols “.” and “@” must not be next to each other
- The symbol “.” or “@” must not be at the beginning or end of the address In addition, the Email Address must not contain the following symbols: “=”, “_”, “-“, “+”, “&”, “<”, “>” or “,”.
I tried writing a query and I have considered all the above point except the at least 6 character condition. I am getting the results but all of them is getting displayed as invalid, I am not sure why.
Below is the query that I wrote:
SELECT EmailAddress
CASE WHEN EmailAddress Like '%^[A-Za-z0-9._%\-+!#$&/=?^|~]+@[A-Za-z0-9.-]+[.][A-Za-z]+$%' THEN 'Valid'
ELSE 'INVALID' END
AS valid_email
FROM Database
Where EmailAddress is not null
[email protected]be treated as valid? Note that RFC2606 tells us that nothing with domain ending.invalidshould ever work. How about:[email protected](could exist but domain is not currently registered)? How about:[email protected](domain is valid but there is no such local part currently) ?