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 all zeros in a text field

Hi Developers,

Need a help to achieve below functionality. 
how to write a validation rule such that it should not allow any special characters(!@#$%^&*) and not allow all zeros in a field. (eg: 0 or 00 or 000 or 0000). 

I have used the below validation rule that is restricting special characters but allowing all zeros. 
NOT(REGEX(Phone__c,"^[a-zA-Z0-9]*$"))
Best Answer chosen by Swetha S415
Yash VoraYash Vora
Hi Swetha,
 Correction to the previous reply.

OR(NOT(REGEX(test__c,"^[a-zA-Z0-9]*$")),REGEX(test__c,"^[0]*$"))

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Swetha,

Greetings to you.

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


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
Yash VoraYash Vora

Hi Swetha,
This will work.
OR(NOT(REGEX(test__c,"^[a-zA-Z0-9]*$")),REGEX(test__c,"^[0-9]*$"))

Kindly select it as the best answer if it works.
Thanks
Swetha S415Swetha S415
Hi Khan Anas,

Hope you are doing good!

The phone field should accept zeros but should not accept all zeros.
Accceptable: 90807543
Not Acceptable: 000000

Regards,
Swetha
Swetha S415Swetha S415

Hi Yash,

Thank you for your valuable reply. But the validation is firing if it contains at least one zero.
The validation should not fire if it contains zero it should fire if it contains all zeros.

 

Regards,
Swetha

Yash VoraYash Vora
Hi Swetha,
 Correction to the previous reply.

OR(NOT(REGEX(test__c,"^[a-zA-Z0-9]*$")),REGEX(test__c,"^[0]*$"))
This was selected as the best answer
Swetha S415Swetha S415

Thank you, Yash!

It worked.

Regards,
Swetha