0

I want to restrict the user from entering the special character '|' (pipe) in any name field or data entry fields.

The check should happen from the screen itself and not through RPG/RPGLE program (as described here

How to prevent user from entering special characters (like symbols not visible in keyboard) in a text field (Character type)?)

I have tried using the VALUES() function in the display file,which only allows those characters mentioned in the function; for ex.

VALUES('A' 'B'...)

and not keeping '|' in it to disallow it, but it becomes very restricted, as one might disallow something which he should not.

Community
  • 1
  • 1
Saad
  • 93
  • 2
  • 9
  • Unless the input fields are only one character wide, VALUES() can't help. A display file doesn't have the capability you're asking for, and it would not be good practice in any case. Far better to validate the data in a validation program. – user2338816 Dec 16 '14 at 13:02

2 Answers2

3

I think the easiest method would be to do an edit check at runtime instead of trying to get your workstation to do the edit.

David G
  • 3,940
  • 1
  • 22
  • 30
3
  1. Why should this edit check happen at all? Is it because you are exporting a table and the export routine doesn't escape the pipe? If so, fix the export routine!
  2. Having said that, there are plenty of reasons one really doesn't want special characters in the data, and what we have learnt over the years is that application programs are not the only way to get data into a file. There are utilities like DBU and WRKDBF, there are transfer applications like FTP and Client Access file transfer, there are external protocols like ODBC which allow Excel, web applications, and other external applications which can reach into your database. Finally, there are stored procedures and other programs on your own system which can bring data from other files - files which have not been 'cleaned' of these special characters.

I think @david has the right answer - check the data at runtime. The way I would implement this is with a trigger. That way, no matter what tried to insert or update your field with a special character, the database itself would reject the attempt.

Buck Calabro
  • 7,558
  • 22
  • 25
  • Hi Buck. 1. The edit check should happen because we are getting CRAP data in from Upstream for some data. The '|' is being sent in proper form, but it is somehow getting junked out during XML mapping in the middleware end. 2. As @David pointed out, it can be done at runtime, but performing the same from the workstation would cause less hassles, as there are a lot of possible areas through which such values could be sent. Having said that, I would like to proceed as suggested by you guys and will get back with the results. – Saad Dec 16 '14 at 04:38
  • 1
    The solution is probably a combination of solutions based on where the bad characters are coming from. My big issue was Unicode characters coming from a java application where people were pasting text from MS Word. You really need to understand the source of the issues before you start deleting bits and pieces of the text. – jmarkmurphy Dec 16 '14 at 05:36