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
Deepak Sharma 12Deepak Sharma 12 

Text validation rule in salesforce

I am new to salesforce. Please help me out.Create a text validation rule to require username value to be 9 characters only.
Best Answer chosen by Deepak Sharma 12
Jason Curtis NBSFDGJason Curtis NBSFDG
David, you are right, sorry, I was looking in the wrong place for validation rules, use to them being on the object page!
Also, just to clarify, your logic would require all usernames to be exactly 9 characters. In case Deepak meant no longer than 9 characters he could use:
LEN( Username ) > 9
And usernames always have to be in the form on an email address, so by default you will be using characters "@" and ".". Plus two characters, i.e. xxxxx@a.a This could get tricky, you would only have 5 characters before the @.

All Answers

Jason Curtis NBSFDGJason Curtis NBSFDG
Hi, Deepak, are you trying to modify the Username field on the User object? Username is a standard Salesforce field and you cannot put any validation on it, or any validation on the user object.
With regular text fields you can specify the length, though. And on other objects you can create validation rules that make sure user supplied data meets certain criteria, but again, not on the user object (is it special).
David "w00t!" LiuDavid "w00t!" Liu
I honestly don't know why you'd want to do this, but this will work!

LEN( Username ) != 9

Just tested successfully in my org!
Jason Curtis NBSFDGJason Curtis NBSFDG
David, you are right, sorry, I was looking in the wrong place for validation rules, use to them being on the object page!
Also, just to clarify, your logic would require all usernames to be exactly 9 characters. In case Deepak meant no longer than 9 characters he could use:
LEN( Username ) > 9
And usernames always have to be in the form on an email address, so by default you will be using characters "@" and ".". Plus two characters, i.e. xxxxx@a.a This could get tricky, you would only have 5 characters before the @.
This was selected as the best answer