Constraint problem : regular expression

  • Hello !

    I'm a n00bi with SQLServer and I have a problem with a regular expression constraint.

    I've an attribute typed "int" in a table.

    I add a constraint to this attribute :

    ([myAttribute] like '[\-+]?[0-9]+')

    But when I try to insert in my table a row containing the value 7 for this attribute, I get an error which tells me that I don't respect this constraint.

    Where is the problem ?

    Thanks for your response

  • I'm not really up on constraints but one thing jumps right out at me.

    The regular expression '[\-+]?[0-9]+' simply says that this is a either a negative or a positive integer.

    This being the case wouldn't it be easier to use isnumeric(column_x)=1 ?

  • It looks to me that the way your regular expression is written you will have to add a plus sign in front of the 7 that you are trying to insert.

    Like this: +7

    isnumeric() will validate that a numer is being inserted, however it will not check to see if it is an integer.

    In either case, this is all built in SQL Server functionality. If you try to insert non-integer data, you'll get an error message.

    So what is it that you are trying to do?

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply