Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Which is the best REGEX for name validation?

Asked by Elizabeth Clarke Jun 6, 2023 1.7K views 1 answer
Share

About this question

Looking to stop people putting initials in the First / Last name fields, plus any special characters that you would not associate with a name. I've got something, although it is coming unstuck on names like McGowan or MacGowan. I understand why although I'm stumped to provide a solution.

This is what I have:

AND( $User.ProfileId <> '00e30000001jDdz', OR( LEN(FirstName ) <=1, MID(FirstName ,2,1) = " ", NOT( REGEX( FirstName, '([A-Z][a-z]*)([\s\'-][A-Z][a-z]*)*' ) ) ) )
The UserProfile is to let a System Admin do what they want. The Len & Mid bits are to stop initials, or people putting in "S J ".
There is probably a more elegant way of doing this but I'm rather new to REGEX.

Any suggestions on how to improve this?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.