SQL Question:Write an SQL query that checks for email addresses with at least 8 alphabetic characters before the "@"

SQL Question:Write an SQL query that checks for email addresses with at least 8 alphabetic characters before the "@"

 SQL Query:  Write an SQL query that checks for email addresses with at least 8 alphabetic characters before the "@" .

 Youtube Video :-- video

Input

 

Output

manvit@1

 

Invalid

manvitla@2

 

valid

manvitla#2

 

Invalid

manvitlay@1

 

valid

manvit@1ys

 

Invalid

manvitl@y1

 

Invalid

 

 

Oracle & MySQL

with cte as (

select 'manvit@1' as email from dual union all

select 'manvitla@2' as email from dual union all

select 'manvitla#2' as email from dual union all

select 'manvitlay@1' as email from dual union all

select 'manvit@1ys' as email from dual union all

select 'manvitl@y1' as email from dual

)

select email,

  case  when REGEXP_LIKE(email, '^[A-Za-z]{8,}[^@]*@')=1

    then 'valid' else 'invalid' end result

from cte;

 

 


PostgreSQL

with cte as (

select 'manvit@1' as email union all

select 'manvitla@2' as email union all

select 'manvitla#2' as email union all

select 'manvitlay@1' as email  union all

select 'manvit@1ys' as email  union all

select 'manvitl@y1' as email

)

select email,

  case

    when email ~ '^[A-Za-z]{8,}[^@]*@' then 'valid' else 'invalid' end result

from cte;

 


Explanation:

 

 

REGEXP_LIKE(email, '^[A-Za-z]{8,}[^@]*@'): This condition checks if:

^: The string starts with.

[A-Za-z]{8,}: At least 8 alphabetic characters (both uppercase and lowercase).

[^@]*: Any number of characters that are not @, ensuring that the sequence continues until the @.

@: The presence of the @ symbol following the alphabetic characters.

Post a Comment

0 Comments