View Full Version : how to avoid space in input field
gvanassche
10-11-2009, 05:20 AM
All,
I'm trying to make a small app that allows people to enter text in an input box.
I want to avoid that some characters are use (? * \ / ...). I can do this by using the input mask ?????????
I also want to avoid the SPACE to be entered. I did not see an option to do this.
So I tried to use FIND on the string, but for a reason I do not understand the space is always found as the last character, even when it was not entered.
Does anyone have a solution for this? Or, is my observation wrong?
thanks
gert
RizlaUK
10-11-2009, 05:38 AM
http://www.indigorose.com/forums/showthread.php?t=17451&highlight=filter+key
Edit:
in AMS 7.5 use the below function
function FilterKeyPress(InputObject, e_Key, sAllowed)
sOrig = Input.GetText(InputObject)
sFilter = String.TrimLeft(sOrig, sAllowed)
sFilteredLeft = String.TrimLeft(sOrig, sFilter)
sFilteredRight = String.TrimRight(sFilteredLeft, sFilter)
Input.SetText(InputObject, sFilteredRight)
Input.SetSelection(InputObject, String.Length(Input.GetText(InputObject)) + 1, String.Length(Input.GetText(InputObject)))
Input.SetSelection(InputObject, -1, 1)
end
gvanassche
10-11-2009, 05:49 AM
whaw.... This is a very usefull trick!
thanks a lot.
gert
azmanar
10-11-2009, 11:56 AM
Hi Gert,
You have another option that you can use together.
I have an example in my website to filter out any character (including space) that you want from user submissions.
The function is like a REGEX ( regular expression ).
You can adjust the function for various kinds of INPUT:
1. Numbers only
2. Alphabets only
3. Alphanumerics only
4. Alphanumerics + other DEFINED characters
5. Correct positions and number of defined characters
6. etc for whatever you fancy.
When user submit, the input will be checked and prompted with advice to correct specific errors, if any.
beware of cut and paste. It doesn't fire the keypress event. You'll need to parse that differently.
gvanassche
10-28-2009, 03:03 PM
Worm, right! I discovered that one as well, so I check the fields before I allow the OK button to be clicked.
thanks
gert
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.