+ Start a Discussion

can any one give me a example for validation of a input text field in vf page through a button.please help me

1) when i will enter any wrong data to the input text field and click the button , it shold show an error message below the field.

2)when i should enter the correct data to the input text field, and click the button, it should call the action method of that button which is writtten in controller.
Anshul GoyalAnshul Goyal
1.you have to call a javascript function on button click.
2,Then check validation in javascript function and if it is true call actionfunction as

function checkValidation(inputVal){
   if(inputVal value is correct as per validation)
      //call action function
  show message by rendering text into some div below your text field


<apex:actionfunction name="actionFun"  action="controllerMethod"/>

PrasanntaPrasannta (Salesforce Developers) 
In order to validate the input text field in vf page, we need to make the field as required that shows the red bar.
Here is the example to make two input text field as required that checks the validation on the click of save button.
<apex:page StandardController="Account">
<apex:form >
<apex:PageBlock >
<apex:PageBlockSection >
  <apex:pageBlockSectionItem >
  <apex:outputLabel value="AccountName"></apex:outputLabel>
  <apex:outputPanel >
  <div class="requiredInput">
  <div class="requiredBlock"></div>
  <apex:inputText label="Account Name :" value="{!account.name}" required="true"></apex:inputText>
  <apex:commandButton action="{!save}" value="Save"/>

Hope this example helps.
Could you provide an example using javascript ?