0

For a date field , I know I can put validate like this :

<apex:outputText label=" Date" value="{0,date, MM'/'dd'/'/YYYY}" >
                        <apex:param value="{!item.Date__c}" />

But this might have loopholes in it like 02/03/2017 entered manually may maean different in US and say UK format . Is there any other validation that can be added through VF page or apex code ? Not asking about any JS solution.

SFDCRookie
  • 847
  • 3
  • 22
  • 33
  • 2
    You can display it differently based on the user locale. Not sure what you mean by validation as this is not an input? – Jesse Milburn Feb 02 '17 at 16:35

1 Answers1

0

I suppose you meant <apex:inputText... /> instead of <apex:outputText .../>. You could use jquery datetimepicker. Download the library, include in your VF page, apply dateTimeField class to your <apex:inputText.../> and execute below code on page load:

function setPickers(){
        $('.dateTimeField').datetimepicker({
            lang: 'en',
            format: 'd.m.Y H:i'
        });
    }

You'll have a really nice-looking jquery-based datetime pickers. Nevertheless it would be good to check data in apex too:

try {
    Date dt = Date.parse(dateFromVFPage);
} catch (Exception e) {
    System.debug('Not a date!');
}
EvAzi
  • 1,041
  • 9
  • 23
  • Thanks EvAzi . Talking about the Apex solution . Wouldn't the Salesforce internal message be shown before the custom code that I will be putting? – SFDCRookie Feb 03 '17 at 05:41
  • My scenario - For a date field user enter 9/9/209 it is changed to 9/9/2209 even before Save – SFDCRookie Feb 03 '17 at 05:45
  • @SFDCRookie quite don't understand your question. If user enters 9/9/209, salesforce will show "Not a date!". – EvAzi Feb 03 '17 at 10:38
  • In any datepicker field , if I enter 9/9/178 manually , Salesforce will change it to 9/9/2178 – SFDCRookie Feb 03 '17 at 10:54