Date and number formats

I am designing a database and I am looking for a way to make the date auto-format. Sorry I know this must be brain dead simple but it loses me. When they enter 101007 for example I want it to read 10/10/2007 with a refresh immediately, or at worst as the form is saved.

Also for my phone number entries I want when they input 3211234567 for it to automatically show (321) 123-4567. Last but not least I would like a field formatted for Social Security number input to change from 999999999 to 999-99-9999. If I only get an @command or something I can figure it out from there

Again I know this is brain dead simple and thank you for your time.

Rick

rbushey@cfl.rr.com

Subject: date and number formats

You’re opening a can of worms there, Rick - why not just use a date field? That way a user has to put the date in correctly. In order to auto-format you’d need something in the Input Translation like:

@if(@length(field)=6&@isnumber(field);@left(field;2)+“/”+@left(@right(field;4);2)+“/”+@right(field;2);field)

and then something similar in LotusScript on Exiting element - especially if you want it to happen without refreshing or saving.

It’s similar with the phone number - There are so many variations the user could enter, you’d have to code for each situation - nasty.

Subject: RE: date and number formats

I was about to post a very similar answer, but finally decided, that this is not what rick wants to hear. But it is still true. There WILL be times when this logic fails and then they’ll send you fishing (to stay in the picture).

If anything, you might (and just might!) get away with JavaScript functions. However, the client does not support the more usefull events like onKeyPress, onKeyUp or onKeyDown, so you are limited to onChange, which will not fire until you enter the next field of refresh the form. A basic version - without any error checking, so don’t even think about using it as is - could look like so for the date fields:

var thisValue = this.value;

var month = thisValue.substring(0, 2);

var day = thisValue.substring(2, 4);

var year = thisValue.substring(4, 6);

var newValue = month + “/” + day + “/” + year;

this.value = newValue;

The one advantage over a native input translation is, that you could still use this in a Date field.

A more fancy approach could be to start a call to a function that recursively calls itself every XX milliseconds in onFocus and stop that function in onBlur. This function would have to check the current value of the field, apply error checking and “input translation” and call itself using setTimeOut().

But again, this is not a recommendation. I’d rather suggest to stay away from it, if you can.

Subject: RE: date and number formats

Following up on Harkpabst’s suggestion, you could use JavaScript regular expressions to match a variety of formats.

Google javascript and regexp together with “phone” (or “ssn”) and I’m sure you will find a few possible suggestions.