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
mac adminmac admin 

How to change the manually entered data i a text field as i required

Hi everyone,
-I want to enter the date manually in a text field (10chr). I want to validate it as the date formate as below _ _/_ _/_ _ _ _.
Can anyone help me over here.
thanks in advance.
Regards,
mac.
Pruthvi KankunthalaPruthvi Kankunthala
You can convert text to a Date so you can use the string value with your other Date fields and formulas. You’ll want your text to be formatted as “YYYY-MM-DD”. Use this formula to return the Date value:
DATEVALUE( "YYYY-MM-DD" )
 
SandhyaSandhya (Salesforce Developers) 
Hi,

You can write validation rule on your object 
NOT(REGEX(custom_date__c,"[0-9]{1,2}[/]{1}[0-9]{1,2}[/]{1}[0-9]{4}"))
so that if the date is other than _ _/_ _/_ _ _ _. This format you throw an error saying date should be in below above format.

User-added image


Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya

 
sandeep reddy 37sandeep reddy 37
apex class 



public class dateinput {
    public integer day{set;get;}
    public list<Opportunity > op{set;get;}
    public string name{set;get;}
    public string stage{set;get;}
    public integer month {set;get;}
    public integer year{set;get;}
    public date input{set;get;}
    public  dateinput(){
        op=new list<Opportunity>();
        
    } 
    public void input(){
        input=date.newinstance(year,month,day);
        Opportunity p=new Opportunity();
        p.Name=name;
        p.StageName=stage;
        p.CloseDate=input;
        op.add(p);
        insert op;
    }
}
 vf page 



<apex:page controller="dateinput" docType="HTML-5.0" >
    <apex:form>
        <apex:pageBlock> <apex:pageBlockButtons>
            <apex:commandButton value="save" action="{!input}" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="2">
                <apex:outputLabel value="opp name"></apex:outputLabel>
                <apex:inputText value="{!name}" />
                <apex:outputLabel value="opp stage"/>
                <apex:inputText  value="{!stage}" />
                <apex:outputLabel value="opp closedate"/>
             <apex:input type="date"  value="{!input}" />
                </apex:pageBlockSection>
        </apex:pageBlock>


do like this 
mac adminmac admin
Hi Sandya,
Can we seperate the numbers with '/' while entering the value in the field.
SandhyaSandhya (Salesforce Developers) 
Hi Mac,

I suggest you use date field instead of text field which has all standard properties you are mentioning.

Thanks and Regards
sandhya