Validating input of an email address
Validating input of an email address
www.mvsforums.com/.../viewtopic.php
Validating input of an email address
The sample code from 2006 is a good starting point. Just make sure you update it to recognize the expanded list of valid domains that exist today as well as formatting to accept valid country codes.
Validating input of an email address
Thanks for the replies
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:
http://regexlib.com/Search.aspx?k=email
or 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.
Validating input of an email address
Validating input of an email address
RFC 5322 allows a vast range of possible address expressions, some of which aren't actually usable in practice. This page gives a regex which the author claims accurately matches RFC 5322's "preferred" syntax:
www.regular-expressions.info/email.html
... but the author then goes on to explain why you shouldn't use it.
It also doesn't seem to support angle-addrs. Most of the regexs I've seen for this purpose don't. And, personally, my feeling is that if you don't support angle-addrs, you have a usability issue, because some MUAs like to put an angle-addr in the clipboard when you copy an email address. Not handling angle-addrs is like not allowing hyphens in credit-card numbers: you're forcing the user to do a job that the machine can do trivially.
But maintenance is the greatest concern. I use regexes every day (because vim is my editor of choice), but I try to avoid them in code. And when I do use them, I break them up into short, well-commented sections. Regular expressions are very difficult for most people to read and reason about - particularly the "extended" regular-expression syntax popularized by Perl, which defines things that are formally equivalent to Turing machines (real regexes are only DFA-equivalent) and consequently have nasty potential problems like not halting.
In this case, I don't see any good reason to use a regular expression. Implement individual tests. There aren't that many of them, and the OP listed a bunch (exactly one @ character, etc). They aren't hard. They will be very easy for a maintainer to understand and update.
RFC 5322 allows a vast range of possible address expressions, some of which aren't actually usable in practice. This page gives a regex which the author claims accurately matches RFC 5322's "preferred" syntax:
www.regular-expressions.info/email.html
... but the author then goes on to explain why you shouldn't use it.
It also doesn't seem to support angle-addrs. Most of the regexs I've seen for this purpose don't. And, personally, my feeling is that if you don't support angle-addrs, you have a usability issue, because some MUAs like to put an angle-addr in the clipboard when you copy an email address. Not handling angle-addrs is like not allowing hyphens in credit-card numbers: you're forcing the user to do a job that the machine can do trivially.
But maintenance is the greatest concern. I use regexes every day (because vim is my editor of choice), but I try to avoid them in code. And when I do use them, I break them up into short, well-commented sections. Regular expressions are very difficult for most people to read and reason about - particularly the "extended" regular-expression syntax popularized by Perl, which defines things that are formally equivalent to Turing machines (real regexes are only DFA-equivalent) and consequently have nasty potential problems like not halting.
In this case, I don't see any good reason to use a regular expression. Implement individual tests. There aren't that many of them, and the OP listed a bunch (exactly one @ character, etc). They aren't hard. They will be very easy for a maintainer to understand and update.
Never late than never.
Maybe the small code in the zip file can be usefull. It's derivated from the example given in this thread.
Two programs : called by a "call" or as a function.
It can probably be ameliorated.
Regards
Alain
Never late than never.
Maybe the small code in the zip file can be usefull. It's derivated from the example given in this thread.
Two programs : called by a "call" or as a function.
It can probably be ameliorated.
Regards
Alain
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
PRD-COUNT =1
PERFORM MY-ROUTINE-USING-EMAIL.
You could go further with INSPECT and test where in the string those fields are and make sure the period comes after the @ sign.
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
PRD-COUNT =1
PERFORM MY-ROUTINE-USING-EMAIL.
You could go further with INSPECT and test where in the string those fields are and make sure the period comes after the @ sign.
more than one period in a valid email address, both before and after the @
sign. For example (from the first Sherlock episode),
**PERSONAL INFORMATION REMOVED** has three periods and is a valid email format.
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
PRD-COUNT =1
PERFORM MY-ROUTINE-USING-EMAIL.
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.cthe other one :
cob -x test-fnemailcheckwithregex.cbl fnemailcheckwithregex.cbl fnztrim.cbl fnregex.cYou 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-ifYou 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 !
Regards
Sign up
Already have an account? Login
Welcome to the Rocket Forum!
Please log in or register:
Employee Login | Registration Member Login | RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.