Validate Visualforce form in lightning speed using VFValidator

While working on custom development, I found that form validation is the essential need for any developer in terms of data quality. I took a couple of hours to write code for the validation whether it is client side or server side and which gave me an idea to come up with a generic solution which can be used by any developer. To come up with a generic solution, I created one Visualforce component which can be embedded in any Visualforce page to validate the form.

Using VFValidator, you can do the common form validations. I am trying to evolve this as much as I can. I will try to keep my post very simple so everyone can be benefitted.

How to use VFValidator

Using VFValidator is very straightforward and quick. You just need to embed the VF component in your Visualforce page. Here is the syntax.

<c:VFValidator formId="FORM_ID"/>

FORM_ID : Form where you want to have the validation. 
By default its "frm" if you are not passing the ID.

After embedding the component, you will have to use some specific classes with your input components. Each class has its own purpose and there are limited classes which you can use. Here are the details about each class and its purpose.

  • required : To make a field required
  • email : To check the validity of the email address
  • phone :  To verify a valid phone number, only allows 123-456-7890 format
  • number  : To restrict field for digits only
  • password: To check the password strength, Must be 8 characters and must contain 1 digit and special character

VFValidator Sample code

<apex:inputText id="firstName" styleClass="required slds-input" value="{!Contact.FirstName}"/>


If you want to check the demo of VFValidator then here is the VFValidator DEMO Link. I have also created a GitHub repository.

Please feel free to give your feedback. Thanks in advance!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.