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
vicky2489vicky2489 

validate

i need the validation for the name field.it should not contain numbers and special characters.

<apex:page controoller=""s>

<apex:pageBlockSectionItem >Name:</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem ><apex:inputText value="{!name}" id="name"/></apex:pageBlockSectionItem>
<apex:pageblockButtons >
<apex:commandButton value="save" action="{!find}"/>
</apex:pageblockButtons>
</apex:page>

public class S
{  
    public string name{get;set;}

sapthagiri_186sapthagiri_186
<apex:Form id="Form_ID">
<apex:messages title="Errors Occured" styleClass="errorMsg" style="font-family:verdana,garamond,serif;" />
          <apex:pageBlock id="PageBLock_ID1" mode="edit">
              <apex:pageblocksection  columns="2"  collapsible="false">
	          <apex:pageBlockSectionItem >                        
	              <apex:outputLabel value="First Name" style="position:relative;float:left;"/>
		         <apex:outputPanel styleClass="requiredInput" layout="block" style="position:relative;left:2px;"> 
			<apex:outputPanel styleClass="requiredBlock" layout="block"/>
			     <apex:inputField value="{!AccountInfo.Name}"/>
			</apex:outputPanel>                        
		    </apex:pageBlockSectionItem>
		</apex:pageblocksection>
	<apex:commandButton value="Save" action="{!SaveAccount}" reRender="Form_ID"/>         
     </apex:pageBlock>
</apex:Form>

public class AccountInfo
{	
    public Account AccountInfo = new Account();
    public Account getAccountInfo()
    {
        return AccountInfo;
    } 
    public void SaveAccount()
    {
         if((AccountInfo.Name == Null || AccountInfo.Name == '')
         {
             ApexPages.Message msgAddr = new ApexPages.Message(ApexPages.severity.Error,'Enter required fields');
             ApexPages.addMessage(msgAddr); 
  	 }  		
         else
  	 {  	
	     insert AccountInfo;
	 }
     }
}

 Hey, try this code..

Sridhar BonagiriSridhar Bonagiri

Hi,

 

Use REGEX to validate for numbers and special characters in the name field.

 

Regards,

Sridhar Bonagiri

If this post is your solution, kindly mark this as the solution and give Kudos.