How to avoid inserting special characters in a SQL Server column?

I need to create a restriction in SQL Server that prevents inserting special characters into the firstname column.

I have tried to create it this way:

ALTER TABLE [CTPlatform].[Users] WITH NOCHECK 
    ADD CONSTRAINT [CK_Users_Firstname] 
        CHECK ([FirstName] LIKE '[A-Z]')
GO

But it only allows me to enter one character, example: 'A', 'J', but I need it to allow me to enter 'Jhon', 'Maria'

Upvotes: 1

Views: 1350

Answers (1)

Md. Suman Kabir
Md. Suman Kabir

Reputation: 5453

You can try this :

ALTER TABLE [CTPlatform].[Users] 
ADD CONSTRAINT CK_Users_Firstname 
       CHECK (FirstName NOT LIKE '%[^a-zA-Z]%') 
       

Upvotes: 1

Related Questions