Well, first we need to know the rules for a valid input. For
example, is 25 a valid input? Does it mean 25,00 or ,25? Is ,25 valid or do you require 0,25? Is 1234
valid or do you require 1.234? It is common to accept something
without the cents and without the thousands separator, and then
display the input in a standard format as you showed. Testing for
the 21 character limit might be a test on the input or a test after your standard formatting.
If x is the input, then you can test for the various valid inputs
with something like x?1(.21N,1.3N.(1"."3N)).1(1","2N) This allows (up to 21 digits without dots or 1 to 3 digits followed
by any number of groups of 1 dot and three digits) and then all of
that can be followed by an optional one comma and two digits. Put a dot right after the ? to allow a comma without a leading digit. Tested with this immediate mode test loop:
f r !,"R$: ",x," " q:x="" w
$S($l(x)<22&(x?1(.21N,1.3N.(1"."3N)).1(1","2N)):"OK",1:"NG")