0

I have a input text field for search option. when the input field is empty or contain a single character i need to throw a error message "Input box must contain atleast two characters"

my VF:

<center><apex:inputText id="theTextInput2"  value="{!CityI}" label="City"/> 
 <apex:commandButton value="Search" action="{!Search}"  reRender="tblZoneContacts1"/></center><br></br>

controller:

public void Search(){  
    if(CityI==null || CityI==''){
        Apexpages.addMessage(new Apexpages.Message(ApexPages.severity.INFO, 'search term must be longer than one character:'));
        return;
}

Thanks in Advance

0

You have to include an else part in your code to check for the length of the string Cityl, if it is less than 2 characters. If less than 2 characters then throw an error.

public void Search()
{
 if(CityI==null || CityI=='')
 { 
 Apexpages.addMessage(new Apexpages.Message(ApexPages.severity.INFO, 'search term must be   longer than one character:')); 
 return; 
 }
 else if (CityI.length()<2)
 {
 Apexpages.addMessage(new Apexpages.Message(ApexPages.severity.INFO, 'Input box must contain at least two characters')); 
 return; 
 }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.