Subject Re: insert dash after N characters in a strings
From Heinz Kesting <Nobody@Nowhere.com>
Date Mon, 25 May 2015 19:10:02 +0200
Newsgroups dbase.getting-started

Hi Kent,
> I have this project where i want put dashes in every characters;
> I want that whenever i type on a certain entryfield the system will automatically put dashes in it.
> like 999WYZ999 TO 999-XYZ-999-000 - also 3 zeros will be automatically added ...
> or 999WWXX44E  = 9-99W-WXX-44E
> I hope you can help me.

As Ivar has already pointed out, a little more information about the
validation for this string is needed, like:

- how do you decide where to put the first dash in the example
999WWXX44E  = 9-99W-WXX-44E
How do you determine that the result should be
9-99W-WXX-44E rather than 999-WWX-X44-E (followed by 2?? zeros)
Are leading spaces allowed, or should they be stuffed with leading zeros?

- does it always have to be 4 groups of 3 chars, how do you deal with
shorter or longer strings?

- what about upper/lower case?

- any other chars that are nor allowed, not valid, special chars like
  ? ! § % etc.?

There maybe some further rules of that kind which were to be taken care of.

However, you could start out by setting a simple picture property for
the entryfield like

picture = "NNN-NNN-NNN-NNN"

and setting the max field length to 15 in case you have always 4 groups
with 3 chars seperated by 3 dashes.

maxLength = 15

This would give you the desired dashes automatically. Then, to refine it
you could use key() and onKey() to deal with unwanted/invalid chars.
Finally you could apply all kinds of fine-tuning when the user has left
the entryfield by exploiting the entryfield's onLostFocus event. Here
you can use functions and methods like substr(), at(), stuff() etc. to
validate any part of the entryfield's value and "stuff" it the way you
need to.

This should give a start.
Kind regards, Heinz