You need to sign in to do that
Don't have an account?
how to prompt an error message
Hi,
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..!!!
///////////////////////////Visualforce/////////////////////////
<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/>
</apex:form>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
//////////////////////////////Controller/////////////////////////////////////
public with sharing class mylogin {
public String password { get
{if(password.length>=6)
{ 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;
try{
if(stdlist[0].Password__c==password)
{
reference=new PageReference('/apex/salesofficer');
reference.setRedirect(true);
}
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());
ApexPages.addMessage(msg);
system.debug('------Exception caught----'+e);
}
return reference;
}
public String getUsername() {
return null;
}
}
Hello,
Please refer following blog and link, explaining similar requirement with code snippets:
http://bobbuzzard.blogspot.in/2011/04/field-level-error-messages-with.html
http://boards.developerforce.com/t5/Visualforce-Development/How-to-add-error-message-to-specific-inputText-inputfield/td-p/198411