How to block Characters/Alphabets other than Integer in @N Entry

I have one window in which there are certain fields like quantity, price, shipping charge those are numeric fields but when i open the application i am able to put alphabets there though after entering it gets removed, but is there any option by which i can directly block user from entering anything other than number?
Inshort i only want to allow numbers the field shouldn’t take anything other than that.

Is there any option in the Properties by turning it ON we can achieve this?

Normally the picture token controls what can and cant be input into an entry field.
So I would make sure these fields are using an entry field first (not a text field) and then see what the picture tokens are.

1 Like

Hi, see MASK on the help. It is a windows level property, named EntryPattern on the Windows Designer.

2 Likes

You can put MASK on specific controls rather on the Window when it applies to all controls.

For numbers you’ll also want the INS attribute otherwise data entry will default to Left-to-Right entry which is very odd for an amount or quantity to start entering the high digits first. Also the leading zeros fill in.

Try editing an existing amount using the arrows. I think you’ll find it odd when you press Left the cursor jumps to the left most high digit and fills in leading zeros. You have to press Right, then left works as expected. It works best just to reenter the amount.

Try it some and I think you’ll find MASK makes the control harder to use. You can assign it at runtime with PROP:Mask so it can be optional incase user’s hate it. I never use it.

An ENTRY can have an IMM attribute which sends an event every key stroke. Maybe that could be used to spot invalid characters. I think it works to CHANGE() the entry to not have those and the user can continue typing, I never tried it.

One thing the free entry allows is special invalid values like putting a “T” into a Date field that sets it to Today:

OF EVENT:Rejected
   IF  LOWER(SUB(?{PROP:Text},1,1))='d'    |     !Entry is @D Date picture
   AND LOWER(LEFT(?{PROP:ScreenText}))='t' THEN  !and user typed "T"
      CHANGE(?,TODAY())                          !set Date = Today's date
      DISPLAY
      CYCLE
   END 
   SELECT(?) ; CYCLE  !reject it

You are right, I’ve just tested, on Clarion 10 it can be used on a specific control activating MASK (EntryPattern) for it on the WINDOW definition.

Despite being on the Help, using on a specific control wasn’t working on some previous versions, C5.5 for example. It wasn’t present on the Window Structure Designer UI, and if manually set both Designer and Compiler raise error. I wonder which intermediate version added support for it.

Setting it programatically has some quirks:

Window{PROP:MASK} has to be done after opening the window and doesn’t worth for current controls on the window definition, as stated on the help.

Control{PROP:MASK} is apparently READONLY so it wouldn’t be so easy to set them on runtime to consider users preferences.

I agree the IMM technique can be usesful too, and subclassing too but I don’t think it should be worth in this case.

@anon23294430 @FedericoNavarro @CarlBarnes Thank you so much for the reply. I will check into it.