How to force a user to enter text in a specific format?
I have a DOB field which is only day and month which I want entered as "dd/mm". How can I ensure the data entered is in that format?
You could add a validation rule in Field Options that rejects input with the wrong format.
You can, with FIleMaker 11 or newer, use the OnObjectValidate trigger to perform a script that checks for such errors.
If you work at it, you can even set up the OnObjectKeystroke trigger to perform a script that checks and responds to user input one keystroke at a time, rejecting keystrokes that would violate the required format. Note that this option requires a fairly long script if you want the field to still respond correctly to standard user edit actions like the back and forward delete keys, text selection, arrow keys, etc...
I have never been able to FORCE a user to do anything!
I have been able to HELP or TRAIN them. I find the FEEDBACK method the best.
But if critical...
Enter the Day and Month in separated fields and build the format yourself.
Thanks Phil and Jim for your responses.
OK so maybe FORCE was a little strong.
What I'm wondering is:
Is there a way to enter into the Field Options (or OnObjectValidate) a validation string which will allow only ##/## as valid where # is a digit and the / is literal? I'm hoping this is a really basic question but I haven't been able to work out how to put literal characters into a format.
The OnObjectValidate will certainly be very useful - thanks Phil
Data Entry Masks are not directly supported in FileMaker, but this validation expression may serve:
Length ( self ) = 5 and Length ( Filter ( Left ( Self ; 2 ) ; 9876543210 ) = 2 and Middle ( self ; 3 ; 1 ) = "/" and Length ( Filter ( Right ( Self ; 2 ) ; 9876543210 ) = 2
Thanks. The issue for me using that expression in the field definition of the table was that it doesn't seem to kick in until you leave the record so that wouldn't work.
I did try using the OnObjectValidate which kind of worked. However, I couldn't get the cursor to return to the DOB field. The idea is that if the user enters invalid data they shouldn't be able to leave the field. I did manage to get it to pop up a message but it still moved on.
I tried Go to Field and Go to Object (having named the field's text box) but these didn't have any effect.
OnObjectValidate is executed just prior to a "commit record", therefore no "go to field". If you have FMP advanced, there are serveral public domain Custom Functions, essentially like Phil's calculation that Masks with error checking.
If you notice most web based info "fill ins" , they do an error checking at the end and return a list of errors, which is what I meant by FeedBack method.
I see a lot of Forum problems with date formats such a European, Miltary, US common... etc. This perhaps the most difficult Find check also. I have found 3 separate field saves User Time...
Day Month Year [ 3 separate fields ] is more Universal and you can use Calculations to make dates.
IF you use Exit Script [False] to exit your OnObjectValidate script when an error is detected, you can return the user to the field they are editing.
Don't forget the alternative if you are absolutely set on a "data input mask" type of controlled input: You can write a script that uses OnObjectKeystroke to process each keystroke as it is made by the users. For me, the result is not worth the effort, but it can be done.
Thanks Phil. I can now get that to work.
I take your point Jim about separating the fields. Yes it's much simpler from a programming perspective but for a user it's a bit of a pain. Guess that's the balancing act when writing applications.
It'd be REALLY nice if FM had a mask facility :-)
Thanks for all your help guys.
I would think that two data fields for month and year would make the data entry quite simple for both the user and the developer.
Frankly, I've never really liked data input masks as I find them to usually be too restrictive and thus slow down data entry.
Clearly a discussion to be held over a glass of red perhaps.
Consider that almost all month numbers are single digit but your data mask requires 2. Having to always remember to use that leading zero slows me down.
with a data input mask, entering january, 2012 require pressing 5 keys:
0, 1 , / , 1, 2
with two fields, you need only press:
1, tab, 1, 2
and yet pressing
0, 1, tab , 1 ,2
also enters the data correctly and you can even use a script trigger to allow the / to move the cursor to the year field. (and an auto-enter calc can add the missing leading zero if you need it.)
Retrieving data ...