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

how to write trigger for phone number validation

hi friends,

            how to write trigger for phone number validation

Chamil MadusankaChamil Madusanka


You can use REGEX in apex to accomplish your requiement. Following links will be helpful for you


If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.


If you want to check the format of the phone number then you can go for a validation rule itself instead of a trigger.


You can use the REGEX function to to phone validation.




  I couldnt get what are you asking for and Why trigger? While creating the field you can specify it as "Phone" and if you need a validation to check it should contain 10digits you can write a validation as:


NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))


This validation checks that phone no. is in (123) 456 7890 format.


If this is not your requirement, please tell me you requirement.