I'm trying to allow time only for data entry. I want to avoid as much apex and visualforce as possible for this project. I can certainly do it but I'm trying to keep this full configure for this particular project (short of a few triggers).

Would the standard method to create a time field that allows seamless entry be:

  • have them enter a text datatype
  • then use a validation rule to make sure it's in the correct format
  • then use a formula field to parse into a "time" format to subtract the Start and End time

If so, is there a way I can apply a mask to the field to allow ##:## ** entry?

Otherwise, if there's an easier cleaner way, I'm all ears!


Yes, a validation rule would suffice. I'd personally recommend a REGEX validation rule so you can build in flexible possibilities. You might start with this:

NOT(REGEX(Start_Time__c, '([1-9]|(1[0-2]):[0-5][0-9]( am| pm)'))

This allows 12 hour format with required am/pm. If you want to allow other formats, like 24 hour format, you'll want to play with the regex some more.


Apex recently (a few releases ago) added a TimeClass. I'm not certain how well this is supported under Visualforce, but this would seem to be what you'd want to try using first. That having been said, in the past, I've used text fields to collect time and also used picklists on the half hour, plus AM/PM picklists, then done validation using RegEx for Time entries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.