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
Priya MishraPriya Mishra 

need a specific pattern to display in the field

I Have field call EIN(number type) it has to accept the 12-1234567  formate only means beginning 2 digit dash seven digit only. 

how to write the logic in apex to show the error on the vf page itself please help me out.

thanks in advance.
ANUTEJANUTEJ (Salesforce Developers) 
Hi Priya,

There is a help article that has an implementation of using regex for validation, below is the one that I could build up, can you please try it once:

!REGEX(epin__C,"^(\\d{2}\\-\\d{7}?$"

Help article: https://help.salesforce.com/articleView?id=000334073&type=1&mode=1

This article has an implementation of using the above regex in apex:

https://www.biswajeetsamal.com/blog/how-to-use-regex-using-apex-in-salesforce/#:~:text=Regular%20expressions%20(REGEX)%20is%20a,search%20text%20using%20regular%20expressions.&text=Patterns%20are%20used%20by%20matchers,operations%20on%20a%20character%20string.

Let me know in case if there are any issues and in case if this comes in handy can you please choose this as the best answer so that it can be useful for others in the future.

Regards,
Anutej
David Jordan 25David Jordan 25
Joint torment is likely the most upsetting sensation you can actually feel. It's a dull and consistent inclination that you can't rapidly shake off. The most noticeably terrible part is, you feel it the most around evening time when you have an awkward sleeping pad.You must check best mattress for arthritis in lower back (https://www.readtopten.com/2020/09/best-rated-mattresses-for-arthritis-sufferers.html).
ANUTEJANUTEJ (Salesforce Developers) 
Priya in case if the above response came in handy can you please mark it as best answer so that it can be useful for others in the future.