Skip to main content Skip to complementary content

Testing the created function via the SQL Server editor

Procedure

  1. copy the below code and execute it:
    create table Contacts (
    FirstName nvarchar(30),
     LastName nvarchar(30),
    EmailAddress nvarchar(30) CHECK
     (dbo.RegExMatch('[a-zA-Z0-9_\-]+@([a-zA-Z0-9_\-]+\.)
     +(com|org|edu|nz)',
    EmailAddress)=1),
    USPhoneNo nvarchar(30) CHECK
     (dbo.RegExMatch('\([1-9][0-9][0-9]\) [0-9][0-9][0-9]
    \-[0-9][0-9][0-9][0-9]',
    UsPhoneNo)=1))
    
    INSERT INTO [talend].[dbo].[Contacts]
                            ([FirstName]
                           , [LastName]
                           , [EmailAddress]
                           , [USPhoneNo])
           VALUES
                         ('Hallam'
                        , 'Amine'
                        , 'mhallam@talend.com'
                        , '0129-2090-1092')
                        , ( 'encoremoi'
                         , 'nimportequoi'
                         , 'amine@zichji.org'
                         , '(122) 190-9090')
    GO
  2. To search for the expression that match, use the following code:
    SELECT [FirstName]
         , [LastName]
         , [EmailAddress]
         , [USPhoneNo]
      FROM [talend].[dbo].[Contacts]
      where [talend].[dbo].RegExMatch([EmailAddress],
    '[a-zA-Z0-9_\-]+@([a-zA-Z0-9_\-]+\.)+(com|org|edu|nz|au)')
    = 1 
    
    
  3. To search for the expression that do not match, use the following code:
    SELECT [FirstName]
         , [LastName]
         , [EmailAddress]
         , [USPhoneNo]
      FROM [talend].[dbo].[Contacts]
      where [talend].[dbo].RegExMatch([EmailAddress],
    '[a-zA-Z0-9_\-]+@([a-zA-Z0-9_\-]+\.)+(com|org|edu|nz|au)')
    = 0 

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!