function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mahesh Babu 3Mahesh Babu 3 

Display standard validations on VF page

Hi All,

I am trying to display the standard validation messages on VF page by using page messages components. My code is in below,

VF page:
<apex:pagemessages escap="false" />
<apex:form>
   <apex:inputtext value="{!contactemailvalue}" />
<apex:commandbutton action="{!contactSave}" value="Save Cont" />
<apex:form>

Controller:
Public string contactemailvalue {set;get;}
public pagereference contactsave(){
try{
contact contemp = new contact();
contemp.lastname = 'Sample Contact';
contemp.email.com = contactemailvalue;

}
catch(Exception ex) {   
            apexpages.addmessages(ex);
            System.debug('Error inside catch block');
            return null;
       }
}

Sample: In this, if user provided wrong format of email then showing the error message like in standard format refer the belowUser-added image

My Requirement is to show the only content of the validation message. From above example i want to show only this message
"invalid email address: asasbvudfeyg"

Please help me to solve this 

bob_buzzardbob_buzzard
I've written a couple of blog posts on this in the past at: 

http://bobbuzzard.blogspot.co.uk/2011/04/field-level-error-messages-with.html

and 

http://bobbuzzard.blogspot.co.uk/2011/04/field-level-error-messages-with_29.html

do these help? I suspect you'll either have to parse the exception message yourself or duplicate your validation inside the apex controller.