Created
September 1, 2022 07:07
-
-
Save BirgittaHauser/4108b879cdfa5bc848b44d8fe05db97e to your computer and use it in GitHub Desktop.
Check eMail Address with SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- UDF - Check eMail Address: | |
-- Parameters: ParEmail => EMail Address | |
-- Returns: 0 = Invalid eMail Address / 1 = valid eMail Address | |
-- In Release 7.5 the new Boolean Datatype could be used for the Return Value | |
-- Attention: There might be better regular expression patterns for checking eMail addresses | |
Create or Replace Function YourSchema.CheckEmail (ParEMail Varchar(256)) | |
Returns Integer | |
Language SQL | |
Modifies SQL Data | |
Deterministic | |
Called On Null Input | |
Set Option Dbgview = *Source | |
Begin | |
Declare RegexPattern VarChar(256) CCSID 1208 | |
Constant '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'; | |
Declare Continue Handler For SQLEXCEPTION Return 0; | |
Return Case When RegexP_Like(Trim(ParEmail), RegexPattern) | |
Then 1 | |
Else 0 | |
End; | |
End; | |
Label On Routine YourSchema.CheckEmail(Varchar()) Is 'UDF - Check eMail Address'; | |
Comment On Parameter Routine YourSchema.Checkemail (Varchar()) | |
(Paremail Is 'EMailAddress'); | |
-- Test | |
Values(CheckEMail('[email protected]')); | |
Values(CheckEMail('[email protected]')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There were some people having problems calling my UDF using my example.
If the UDF schema/library is in the library list (when working under System Naming Conventions)) or in the SQL Path (when working with the SQL Naming Convetions), the UDF does not have to be qualified.
If you want to call the function qualified, the test statements must look as follows: