How to make SQL Server 2008 Check Constraint of a table Allow Only Certain characters?

I’d like to create a check constraint for a table in SQL 2008 which would allow A-Z characters (non case sensitive), numbers, hyphen (-), dot(.), space and underscore (_).
Below is my current expression:
([company_code] not like ‘%[^A-Za-z0-9_ .+]%’).

It fulfills all the above requirements except for hyphen. How could I make the expression allowing hyphen as well?

  • Unicode SQL Query W/ Parameter instead N Prefix
  • SQL: programmatically copy stored procedures from one db to another
  • how to know how many rows will be affected before running a query in microsoft sql server 2008
  • How to display specific database entries into a textbox on a WinForm application
  • Alias .\SQLEXPRESS to (LocalDB)\MSSQLLocalDB
  • Calculating SUM on 3 related tables
  • One Solution collect form web for “How to make SQL Server 2008 Check Constraint of a table Allow Only Certain characters?”

    You can use an ESCAPE clause:

    not like  '%[^A-Za-z0-9_ .+\-]%' escape '\'
    

    The character after the escape character will be matched literally.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.