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

how to prompt an error message


Please help me in prompting error messages in below code.

1: for password field should be 6 digit numeric.

2: for Username or Password Is Incorrect..!!!




<apex:page controller="mylogin" sidebar="false">
    <apex:pageBlock title="UltraVoilet Account">
        <apex:pageBlockSection title="Login">
        <apex:form >
            <b>Username:</b> <br/>
            <apex:inputText required="true" id="username" value="{!userid}" /> <br/><br/>
            <b>Password:</b> <br/>
            <apex:inputSecret required="true" id="password" value="{!password}"/> <br/><br/>
            <apex:commandButton value="login" action="{!login}"/> <br/><br/>

            <apex:outputLink value="{!forgetpassword}">Forget Password?</apex:outputLink> <t/>








public with sharing class mylogin {

    public String password { get
                                    { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'password field should be 6 digit numeric..!!!'));
                                } set; }
    public String userid { get; set; }
    public String forgetpassword { get; set; }
    public PageReference forgetpassword() {
        return null;

    public PageReference login() {
        list<UV_Account__c> stdlist=[select id, Name, Username__c, Password__c from UV_Account__c where Username__c=:userid];
       PageReference reference;
        reference=new PageReference('/apex/salesofficer');
        else ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Username or Password Is Incorrect..!!!'));
        catch(Exception e){
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'Exception - ' +e.getMessage());
            system.debug('------Exception caught----'+e);
        return reference;

    public String getUsername() {
        return null;