Tag Archives: Input Field

Restrict Numbers And Special Characters In Visualforce Page Input Field

Sample Code:

<apex:page standardController="Lead" docType="html-5.0">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection>
                <apex:inputField id="firstname" value="{!Lead.FirstName}" onkeypress="return (event.charCode > 64 && event.charCode < 91) || (event.charCode > 96 && event.charCode < 123)" />
                <apex:inputField id="lastname" value="{!Lead.LastName}" onkeypress="return (event.charCode > 64 && event.charCode < 91) || (event.charCode > 96 && event.charCode < 123)" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Input Field Placeholder in Visualforce Page

We can use html-placeholder="name" attribute for input field placeholder in Visualforce Page.

Visualforce Page:

<apex:page standardController="Account">
    <apex:form>
        <apex:sectionHeader title="Account"/>
        <apex:pageBlock title="Account Information">
            <apex:pageBlockSection >
                <apex:inputField value="{!account.Name}" html-placeholder="Account Name"/>
                <apex:inputField value="{!account.AccountNumber}" html-placeholder="Account Number"/>
                <apex:inputField value="{!account.Site}" html-placeholder="Account Site"/>
                <apex:inputField value="{!account.Phone}" html-placeholder="Phone"/>
            </apex:pageBlockSection>         
        </apex:pageBlock>
    </apex:form>
</apex:page>

Output: