Skip to main content
Numa Roch (Circet) a posé une question dans #Validation Rule

The following REGEX works in https://regex101.com/ but not in Salesforce.

^[a-z]{6}[0-9a-z]{2}([0-9a-z]{3})?\z

Source: https://stackoverflow.com/questions/15920008/regex-for-bic-check

 

It checks whether a given BIC :

  • has 8 or 11 characters, of which
  • first 6 must be alphabetic (4 bank code + 2 country code)
  • next 2 must be alphanumeric (location code)
  • last 3 are optional, alphanumeric (branch code)

Examples

Correct: AGRIFRPP882

Correct: NOLADE21STS

Correct: OPSKATWW

Incorrect: OPSKATW

Incorrect: AABB12CC

 

When using REGEX in Salesforce, backslash characters \ must be changed to double backslashes \\ because backslash is an escape character in Salesforce. The expression must also be put within quotation marks. See Salesforce help.

 

Thus the validation rule would be: 

NOT(REGEX(BIC__c, "^[a-z]{6}[0-9a-z]{2}([0-9a-z]{3})?\\z"))

 

However, when checking on AGRIFRPP882, which is a correct BIC, the validation rule always fires.

 

  #REGEX #Validation Rule

2 réponses
  1. 2 sept. 2021, 20:03

    Am I bad... the formula allowed only for lower case.

     

    This one works (provided you have a data input flow that cleans the data and puts it into UPPERCASE before validation):

     

    NOT(REGEX(BIC__c, "^[A-Z]{6}[0-9A-Z]{2}([0-9A-Z]{3})?\\z"))
0/9000