Prevent the use of Special Characters in a Text input
This process prevents a user from saving a range of Special Characters if entered in a Text Input. This may have other application as well as the Text Box example. A working example is shown below
So how does this work?
Firstly do a Collection of all special characters (you can do this at Screen OnVisible) by using their ASCII value ranges.
ClearCollect(
colChar,
ForAll(
Sequence(15),
{FieldNo: Char(32 + Value)}
),
ForAll(
Sequence(7),
{FieldNo: Char(57 + Value)}
),
ForAll(
Sequence(5),
{FieldNo: Char(90 + Value)}
),
ForAll(
Sequence(4),
{FieldNo: Char(122 + Value)}
)
)
This puts 31 Special Characters into the collection under the field FieldNo.
Below is a gallery (with wrap at 4) showing the characters
Note you may want to allow some such as Underscore _ (95) and will have to adjust the above to suit.
Now put this on the OnChange of the Text Box
ForAll(
colChar,
If(
FieldNo in Self.Text,
Collect(
colError,
{CharError: true}
);
Reset(Self)
)
)
NOTE – I had to use a Collection here as a Variable cannot be set inside a ForAll() statement.
Put this on the OnSelect of the Text Box – you could also in addition put this at Screen OnVisible
Clear(colError)
Now put a Label (this is the warning message) on the screen with this as the Text
"Do not use characters " & Concat(
colChar,
FieldNo & ""
) & " here"
and this as the Visible
First(colError).CharError
This all should work as displayed in the model at the top.
One Comment
Kerashin Naidoo
Works really well, thanks for this help!