function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Caleb Kuester 35Caleb Kuester 35 

Is there a way to validate state name for Custom Metadata Type DeveloperName field?

So Custom Metadata Type records must have the DeveloperName field populated by some kind of text. I don't want that field, but without a choice, I decided to use them in a way that is relevant to my case.

My records are for states, so I want my users to have the presence of mind to be able to spell them correctly, including case.

The only option I have is validation rule with regex.

Here is my rule:
 

NOT(REGEX(DeveloperName, "/Alabama|Alaska|Arizona|Arkansas|California|Colorado|Connecticut|Delaware|Florida|Georgia|Guam|Hawaii|Idaho|Illinois|Indiana|Iowa|Kansas|Kentucky|Louisiana|Maine|Maryland|Massachusetts|Michigan|Minnesota|Mississippi|Missouri|Montana|Nebraska|Nevada|New\\sHampshire|New\\sJersey|New\\sMexico|New\\sYork|North\\sCarolina|North\\sDakota|Ohio|Oklahoma|Oregon|Pennsylvania|Rhode\\sIsland|South\\sCarolina|South\\sDakota|Tennessee|Texas|Utah|Vermont|Virginia|Washington|West\\sVirginia|Wisconsin|Wyoming|Washington\\sD.C./"))

The problem is the spaces. Any state that has a space fails validation.

I do not get a different result if I remove the \\s items and use TRIM(), or SUBSTITUTE(x, " ", "")

Has anybody else come across this?
Caleb Kuester 35Caleb Kuester 35

Figured it out. It's:

NOT(REGEX(MasterLabel,"/^z$|^Alabama$|^Alaska$|^Arizona$|^Arkansas$|^California$|^Colorado$|^Connecticut$|^Delaware$|^Florida$|^Georgia$|^Guam$|^Hawaii$|^Idaho$|^Illinois$|^Indiana$|^Iowa$|^Kansas$|^Kentucky$|^Louisiana$|^Maine$|^Maryland$|^Massachusetts$|^Michigan$|^Minnesota$|^Mississippi$|^Missouri$|^Montana$|^Nebraska$|^Nevada$|^New\\sHampshire$|^New\\sJersey$|^New\\sMexico$|^New\\sYork$|^North\\sCarolina$|^North\\sDakota$|^Ohio$|^Oklahoma$|^Oregon$|^Pennsylvania$|^Rhode\\sIsland$|^South\\sCarolina$|^South\\sDakota$|^Tennessee$|^Texas$|^Utah$|^Vermont$|^Virginia$|^Washington$|^West\\sVirginia$|^Wisconsin$|^Wyoming$|^Washington\\sD.C.$|^Puerto\\sRico$|^American\\sSamoa$/"))
-- if anybody's curious

I was also checking the wrong field before.