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
WPCMSWPCMS 

Validation: Field can not contain spaces

I tried searching for this simple formula but could not find anything that would work for me.

 

We have an account code that needs to be manually entered by a user. The field is 12 characters long and should not have any spaces in it. 

 

I tried

 

CONTAINS(Account_Code_c,"")

 

but it doesn't save on anything.

 

What other formula can I use?

 

Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
rubixtiousrubixtious

My Regular Expressions are a little rusty and maybe someone can come up with a better way but you could use this:

 

NOT(REGEX(Account_Code_c, "([^\\s])+"))

 

 

 

All Answers

rubixtiousrubixtious

My Regular Expressions are a little rusty and maybe someone can come up with a better way but you could use this:

 

NOT(REGEX(Account_Code_c, "([^\\s])+"))

 

 

 

This was selected as the best answer
WPCMSWPCMS

I tried

 

NOT REGEX( Account_Code__c ,"([^\\s})+")

 

and it said unclosed character class near index

 

so I tried

NOT REGEX( Account_Code__c ,"([^\\s})+")) (your suggestion)

 

and it says there are too many parentheses

rubixtiousrubixtious

Please copy, paste and edit to taste :)

 

NOT(REGEX(Subject, "([^\\s])+"))

 

The above works correctly.  The formulas that you have posted do not include an opening parentheses after 'NOT'

WPCMSWPCMS

It worked! Thank you.