Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Pass5107 Absent Member.
Absent Member.
3617 views

Has anyone written cobol code to valid entry of an email address I searched the internet on this issue and only .net, c#, and php come up?

Validating input of an email address

0 Likes
6 Replies
DougP Outstanding Contributor.
Outstanding Contributor.

RE: Has anyone written cobol code to valid entry of an email address I searched the internet on this issue and only .net, c#, and php come up?

Here's a thread that contains code to vaildate the format of an email address:
www.mvsforums.com/.../viewtopic.php
0 Likes
ShanePrice Absent Member.
Absent Member.

RE: Has anyone written cobol code to valid entry of an email address I searched the internet on this issue and only .net, c#, and php come up?

FYI, that code will flag many valid email addresses as invalid. It is designed around older USA email addresses like (someone@email.com) as long as the domain ends with ".COM", ".ORG", ".NET", or ".EDU". It doesn't accept older ".INFO" and ".GOV" domains and flags as invalid domains that include a country code (.us, .uk, .eu, etc.). It also won't work with country codes because they have a second "." character (someone@email.co.uk). In addition, there are many valid domains that exist today that don't match the old standard. Some examples include ".doctor", ".shop", ".fitness", ".dog", etc. You can view the entire list of currently valid top level domains at data.iana.org/.../tlds-alpha-by-domain.txt

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.
0 Likes
Pass5107 Absent Member.
Absent Member.

RE: Has anyone written cobol code to valid entry of an email address I searched the internet on this issue and only .net, c#, and php come up?

What I am trying to do is some validation during entry to say at least check to see that only one @ sign is in the string, and at least one standard character before and after the @, and at least one period after the the @ sign. In our case, the entry person would then press an icon to send a test email to the email address with instructions to reply back that the email information is correct. We do not to be responsible for the validation other than the obvious. It sounds like I will need to review the obvious tests from those other languages and convert them to Cobol.

Thanks for the replies
0 Likes
Chuck Edgin Absent Member.
Absent Member.

RE: Has anyone written cobol code to valid entry of an email address I searched the internet on this issue and only .net, c#, and php come up?

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:

http://emailregex.com/

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.

0 Likes
Pass5107 Absent Member.
Absent Member.

RE: Has anyone written cobol code to valid entry of an email address I searched the internet on this issue and only .net, c#, and php come up?

Thanks Chuck I will check the sights and the use of C$RegExp.
0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Has anyone written cobol code to valid entry of an email address I searched the internet on this issue and only .net, c#, and php come up?

Like pretty much all regexes for email-address validation, these are either broken or nearly impossible to maintain.

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.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.