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 

validation for name field

<apex:page controller="Saved" showHeader="false" sidebar="false">
<apex:form id="ss" > 
<apex:messages ></apex:messages>
<apex:pageblock >
<apex:pageblockSection >
<apex:pageBlockSectionItem >Name:</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem ><apex:inputText value="{!name}" id="name" required="true" /></apex:pageBlockSectionItem>
<apex:pageblockSectionItem >Date:</apex:pageblockSectionItem>
<apex:pageblockSectionItem ><apex:inputtext onfocus="DatePicker.pickDate(true, this , false);" value="{!dat}" id="dt"/></apex:pageblockSectionItem>
<apex:pageblockSectionItem >Age:</apex:pageblockSectionItem>                       
<apex:pageblockSectionItem ><apex:outputText value="{!age}" /></apex:pageblockSecti <apex:pageBlockSectionItem >Address:</apex:pageBlockSectionItem> <apex:pageBlockSectionItem ><apex:inputText value="{!address}"/></apex:pageBlockSectionItem> <apex:pageBlockSectionItem >City:</apex:pageBlockSectionItem> <apex:pageBlockSectionItem ><apex:inputText value="{!city}"/></apex:pageBlockSectionItem> </apex:pageblockSection> <apex:pageblockButtons Location="bottom" > <apex:commandButton value="save" action="{!find}"/> </apex:pageblockButtons> </apex:pageblock> </apex:form> <apex:outputLabel value="{!name}"></apex:outputLabel><br/> <apex:outputlabel value="{!dat}"></apex:outputlabel><br/> <apex:outputlabel value="{!age}"></apex:outputlabel><br/> <apex:outputlabel value="{!address}"></apex:outputlabel><br/> <apex:outputlabel value="{!city}"></apex:outputlabel><br/> </apex:page>



public class Saved
{  
    public string name{get;set;}
        
    public Date dat {get;set;}
    public Integer age {get;set;}   
    public string address{get;set;}
    public string city{get;set;}
    public void find()
    {
        Integer temp = dat.daysBetween(Date.Today());
        age = Integer.valueOf(temp/365);
    }
   }





in this i want to do the validation for the name field(it should not contain any numbers ar special characters).if we enter any number it should shoew alert.only alphabets can enter
Subha ASubha A
In the find method write your logic of checking if the string contains numbers using regular expression and add a VF message .
vicky2489vicky2489

im new to salesforce i dont know how to do