Are you saying that you want the first three characters to always be ANY text (AAA or ABC etc) and they must be capitalized and always three and that then the next four characters can only be number and there must be four numbers (or at least 0001) and total length must be exactly 7 characters total?
Yep, that's exactly right! :)
May be so:
IsEmpty ( Self )
Length ( Self ) = 7 and
Length ( Filter ( Left ( Self ; 3 ) ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ) = 3 and
Length ( Filter ( Right ( Self ; 4 ) ; 1234567890 ) ) = 4 and
GetAsNumber ( Self ) > 0
To handle the caps, use auto-enter calculation (replace) with Upper ( Self ).
For validation, use calculation of EDITED:
Length ( Filter ( Upper ( Left ( Self ; 3 ) ) ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ) = 3
Length ( Filter ( Right ( Self ; 4 ) ; "0123456789" ) ) = 4
Length ( Self ) = 7
Provide a message to the user if validation fails showing them how it should be formatted.
This captures the error after the record is committed unless you use it in a script that is triggered OnObjectSave or OnObjectExit. I'd do one or both and then also consider whether a keystroke triggered script that rejects keystrokes that are "out of pattern" might also help here by acting as a kind of "input mask" to prevent miskeys at the moment they occur.
Excellent, thank so much... can you advise what kind of script I can trigger?
There are no script functions that reference validation or caculation. The only thing I can find is "Insert Calculated Result".
You would use OnObjectKeystroke to run a script that evaluates each key as it is pressed and rejects any that don't fit the pattern.
Set Variable [$key ; Get ( TriggerKeyStroke ) ]
If [ $Key = char ( 9 ) or $key = char ( 10 ) or $key = Char ( 127 ) or $key = Char ( 8 ) //tab, enter, delete or Backspace was pressed ]
Exit Script  //accept these keys so field can be edited and/or exited
Else IF [ length ( YourTable::YourField ) > 7 // full pattern has been entered ]
Exit Script [false] // exit script [false] rejects the keystroke
Else IF [ Length ( YourTable::YourField ) < 2 and Length ( Filter ( $key ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) ) ]
Exit Script  // accept key if it is one of 1st three chars and is Upper case A ... Z
Else IF [ Length ( Filter ( $key ; 9876543210 ) ) ]
Exit Script  // accept key if it is one of last 4 chars and 0 ... 9
Exit Script [false] // reject every other key stroke.
Note, You may only want to use Char ( 9 ) in the first IF step, if you use the default behavior setting where tab should exit the field. If you select Enter as a key stroke use Char ( 10 ) and Char ( 13 ) can be used to identify the Return key. All of the keys you choose to test for in this first If step, should also be selected in the Inspector's behavior section on the Data tab.
"You would use OnObjectKeystroke ..."
Depending upon the FM version Parag is using.