<apex:inputField id="inptFldAge" type="text" onchange="checkAge( this )" />
JavaScript
<script type="text/javascript">
var checkAge = function( ele ) {
var age = parseInt( ele.value );
if( age < 18 ) {
window.alert( "Not Eligible for Voting" );
}
};
</script>
Please feel free to ask if you have any more doubts.
Or you can try this.
Please refer the below link for reference.
- https://developer.salesforce.com/forums/?id=906F000000098GjIAI
- http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/
Hope it will be helpful.Please mark it as Best Answer if the information is informative.
Thanks
Rahul Kumar
Use below Code.
Hope this will help you
Thanks
karthik
Visualforce
JavaScript Please feel free to ask if you have any more doubts.