PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV Mobile 2024 → Edit Control - Preventing Characters Being Entered - Mask
Edit Control - Preventing Characters Being Entered - Mask
Iniciado por OGRP, 11,ene. 2018 11:25 - 5 respuestas
Miembro registrado
17 mensajes
Publicado el 11,enero 2018 - 11:25
Hi

This is for Android where custom masks are not available.

I have an edit control and set the input mask to letters + digits. However I also want someone to be able to also enter a full stop.

If I remove the input mask, I have two choices.
1. Remove any unwanted characters after they have finished entering them (i.e. exit from Edit) or
2. Prevent them from entering unwanted characters in the first place.

I would like option 2. Can someone help with some example code that could be used?

Really appreciated.
Publicado el 11,enero 2018 - 13:01
Hi

it's the same code for option 2 than for option 1... You just put it in
the area exeuted each time there is an edit in the field...

This way, if the user enters a forbidden char, it's immediately removed.

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com

Le 1/11/2018 à 5:25 AM, OGRP a écrit :
Hi

This is for Android where custom masks are not available.

I have an edit control and set the input mask to letters + digits.
However I also want someone to be able to also enter a full stop.
If I remove the input mask, I have two choices.
1. Remove any unwanted characters after they have finished entering them
(i.e. exit from Edit) or
2. Prevent them from entering unwanted characters in the first place.

I would like option 2.  Can someone help with some example code that
could be used?

Really appreciated.
Miembro registrado
17 mensajes
Publicado el 11,enero 2018 - 17:25
Hi

Thank you as usual for helping out. It has almost worked. The code I have used under "code" section that says "Whenever modifying EDT_ISSUE". CLRTXT below is a global function that removes any non-required characters. The problem is when you are typing, it resets the cursor back to the start of the edit field so you end up typing backwards.

EDT_ISSUE..Value = CLRTXT(EDT_ISSUE..Value)

I could resolve this by checking if the character exists in EDT_ISSUE..Value before modifying EDT_ISSUE..Value but it will still bring the cursor back to the start of the edit if you enter an invalid character.

Any ideas would be appreciated.
Miembro registrado
17 mensajes
Publicado el 11,enero 2018 - 17:46
I have come close to a working example with the code below. This works perfectly unless the cursor is moved backwards into the middle of text and then the invalid character added. If the invalid character is added at the end of the text then it works perfectly. In the code below to keep it simple I am only searching for one invalid character . This will be expanded to several invalid characters in the final App.

LOCAL
cpos is int = 0

IF Contains(EDT_ISSUE..Value,"@") THEN
cpos = EDT_ISSUE..Cursor
EDT_ISSUE..Value = Replace(EDT_ISSUE..Value,"@","")
EDT_ISSUE..CursorEnd = cpos
END

All help appreciated to get this working.
Publicado el 11,enero 2018 - 19:19
Hi

your code is nearly there... BUT,

you are saving the value of ..cursor and setting the value of
..cursorEND, which is not enough

You also need to set ..cursor

Furthermore, because you are removing a character, and your original
cursor was AFTER that character, you need to restore to cpos-1

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Ready for you: WXShowroom.com, WXReplication (open source) and now WXEDM
(open source)

More information on http://www.fabriceharari.com


e 1/11/2018 à 11:46 AM, OGRP a écrit :
I have come close to a working example with the code below.  This works
perfectly unless the cursor is moved backwards into the middle of text
and then the invalid character added.   If the invalid character is
added at the end of the text then it works perfectly.   In the code
below to keep it simple I am only searching for one invalid character .
This will be expanded to several invalid characters in the final App.

LOCAL
    cpos is int = 0

IF Contains(EDT_ISSUE..Value,"@") THEN
  cpos = EDT_ISSUE..Cursor
  EDT_ISSUE..Value = Replace(EDT_ISSUE..Value,"@","")
  EDT_ISSUE..CursorEnd = cpos
END

All help appreciated to get this working.
Miembro registrado
17 mensajes
Publicado el 12,enero 2018 - 16:52
Hi Fabrice

Thank you very much for your assistance. It has been very helpful. This has now been resolved with the following code which works very well.

LOCAL
cpos is int = 0
cqt is ANSI string = Charact(34)
arrString is array of strings = ["^","%","_","@","/","\","'","&",cqt]

IF Contains(EDT_ISSUE..Value,arrString) THEN
cpos = EDT_ISSUE..Cursor
EDT_ISSUE..Value = Replace(EDT_ISSUE..Value,arrString,"")
EDT_ISSUE..Cursor = cpos - 1
END
Mensaje modificado, 12,enero 2018 - 17:01