简体   繁体   中英

I have a check constraint on my SQL server, how do i set a validation for the Check Constraint in c#?

The definition for the check constraint is

 (NOT [alt_code1] collate Latin1_General_BIN like '%[^-0-9A-Z_/&$!]%')

How do i make that validation in c#? Also, is collate Latin1_General_BIN case sensitive?

private void txtAlt_Code1_Validating(object sender, CancelEventArgs e)
{
    //code
}

You can try with Regular Expression

var regex = @"^[-0-9A-Z_/&]$!";
var match = Regex.Match(input, regex);

if (!match.Success)
{
    // raise error
}

Hi i found this code to be working

Regex regex = new Regex(@"[^-0-9A-Z_/&$!]");
                Match match = regex.Match(input);
                if (match.Success)
                {
                    // raise error
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM