Salesforce Apex

Salesforce

How to add error message in Visualforce page?

Sample Code: Visualforce page: <apex:page controller="Sample" sidebar="false" ><apex:pagemessages /><apex:form >    <apex:pageblock >              <apex:pageBlocksection >            <apex:pageblockSectionItem >Name:</apex:pageblockSectionItem>            <apex:pageblockSectionItem ><apex:inputtext value="{!nam}" /></apex:pageblockSectionItem>                      <apex:pageblockSectionItem >Age:</apex:pageblockSectionItem>                      <apex:pageblockSectionItem ><apex:inputtext value="{!age}" /></apex:pageblockSectionItem>                  ....