Skip to main content
Hello. I need to write a validation that ensures the "name" field on a custom object (called Target) only contains alphanumeric characters or +,-,_. There is no requirement in terms of structure or order of these characters. We just want to prevent special characters from being used. We also only want this validation rule to apply when new Targets are created.

 

This is the validation rule I tried:

 

AND( 

 

ISNEW() , 

 

(NOT( REGEX( Name , "[a-zA-Z0-9_+-]"))) 

 

)

 

However, it seems to fire every time a record is created, regardless of whether or not I think it meets the requirements. Does anyone have any idea on how I should be writing this validation rule? Thank you!
7 respostas
  1. 6 de set. de 2012, 17:46
    Try this, you need to specify how many of the characters to allow in the regex, so this one just requires one or more of the characters.

     

    AND(

     

    ISNEW() ,

     

    NOT( REGEX( Name , "[a-zA-Z0-9_+-]+"))

     

    )

     

    --KC
0/9000