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
Swetha S415Swetha S415 

validation rule to prevent special characters and spaces

Hello,
how to write a custom validation rule such that it prevents special character and spaces, it should allow only alphanumeric characters. But it should not affect any old records until unless user edits that field.

Example:
Not be allowed.
1.Student*&&^
2.Stud ent   
 
Allowed:
1. Student5654

Best Answer chosen by Swetha S415
Khan AnasKhan Anas (Salesforce Developers) 
Hi Swetha,

I trust you are doing very well.

Please use below syntax:
 
NOT(REGEX( Name , "^[a-zA-Z0-9_]*$"))

Here, Name is a text field. You can replace it with actual field.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas