Validating input of an email address
You can find plenty of Regular Expressions on the web for validating the format of an email address.
Have a look here:
These are just a few examples, but a Google search will turn up plenty more. Once you've found a regex you're happy with, you can use it in your ACUCOBOL code using the C$RegExp library routine.
I suspect that provided utility program is good, but it looks like it does a very full-featured check. Here are two simpler snippets that might do the quick-and-dirty check you want:
1. Regular expression: "^[^@\.]*@[^@\.]*\.[^@\.]*$" - basically start of line, NOT at sign or period, then at sign, then more other characters, then period, then more other characters and end of line.
2. In cobol use INSPECT:
MOVE ZERO TO AT-COUNT
MOVE ZERO TO PRD-COUNT
INSPECT MY-STRING TALLYING AT-COUNT FOR "@".
INSPECT MY-STRING TALLYING PRD-COUNT FOR ".".
IF AT-COUNT =1 AND
You could go further with INSPECT and test where in the string those fields are and make sure the period comes after the @ sign.
For the fun, two other ways of testing a valid email address.
One uses a C validation routine, the other uses regex and calls the standard regex library under Linux (we also use it to check English postcodes).
Compile the first with :cob -x test_check_email.cbl fncheck_email.cbl validateEmail.c
the other one :cob -x test-fnemailcheckwithregex.cbl fnemailcheckwithregex.cbl fnztrim.cbl fnregex.c
You can link then to the runtime if you use int/gnt.
Seems complicated but there is only one call in the code :if fnEmailCheck(anEmail) = 1 then *> email valid : do this... else *> email invalid : do that end-if
You don't have to worry about the length of the email string and have one function replacing many statements that you have to duplicate in each program where you want to check an email...
At least, we use it for years (the first) to our utmost satisfaction !