Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Validate email using complex regular expression

YoavNov 4 2020

Hello,
I need to validate the following complex email regular expressions:
NOT(REGEX ( UPPER ( Field ) ,"^[A-Z0-9._%+-/!#$%&'*=?^_`{|}~]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$"))
or
NOT(REGEX( Custom_Email_Field__c ,'([a-zA-Z0-9_\\-\\.]+)@((\\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})'))
I have wrote the following block.
The following email should not be validate by the regular expression, but they are
yoav@-gmail.com
yoav@d-.com
yoav.-yoav@gmail.com
example:
DECLARE
b_isvalid BOOLEAN;
c_isvalid BOOLEAN;
BEGIN
b_isvalid := REGEXP_LIKE ('yoav@-gmail.com','^[A-Za-z0-9]+[A-Za-z0-9._%+-/!#$%&''*=?^_`{|}~]*@[A-Za-z0-9-]+\.[a-zA-Z]{2,4}$');
c_isvalid := REGEXP_LIKE ('yoav@-gmail.com','([a-zA-Z0-9_\-\.]+)@((\[a-z]{1,3}\.[a-z]{1,3}\.[a-z]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})');
IF b_isvalid or c_isvalid
THEN
DBMS_OUTPUT.put_line ('It is a valid email address.');
ELSE
DBMS_OUTPUT.put_line ('It is Not a valid email address.');
END IF;
END;

The output : It is a valid email address.
But it should be : It is Not a valid email address
Please advise
Regards

Comments
Post Details
Added on Nov 4 2020
2 comments
2,429 views