Validating an email address format in CICS

By | September 7, 2014

Faced with the requirement to edit for a valid email address format from a CICS application, one developer was using the java regular expression support which necessitated starting up a JVM Server in multiple CICS regions at about 90MB of storage per region.  I think the developer must have gotten the regular expression to use from the  W3C HTML5 Specification.  He was using something like


The JVM Server storage overhead seemed a bit excessive to me for such a small use, so I’m thinking, why not use the C runtime regexec() function for the regular expression support?  This shouldn’t be any different from my earlier uses of C runtime functions from COBOL programs, except that this would be under CICS.

So I coded up a routine using

 77  ws-validate-email-pattern pic x(133) value                   
-    z"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-
-    "]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-
-    "zA-Z0-9])?)*$".


call 'regcomp'                                
  using by reference ws-preg                  
        by value     ws-regcomp-cflags        
  returning          ws-rc


call 'regexec'                              
  using by reference ws-preg                
        by value     ws-zero                
  returning          ws-rc                  
if ws-rc = zero                             
  move 'Good email:'  to  ws-output-result  
  if ws-rc = 1                              
    move 'Bad email:'   to  ws-output-result
    move 'REGEX error:' to  ws-output-result                        

and low and behold, it didn’t work.  After some trial and error and calls to regerror() to get some diagnostics, I figured out that the regexec() function does not support the (?: ) syntax, Noncapturing Subgroups, which is in the RE pattern the developer was using and which java.util.regex does support.

I was able to get a pattern such as this

77  ws-validate-email-pattern pic x(50) value   

and the earlier pattern with the :? sequences removed

 77  ws-validate-email-pattern pic x(127) value                   
-    "0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-
-    "9])?)*$".

to work.

valemail.cob valemail.jcl

So, if I want to support the non-capturing subgroups, perhaps I could use the Standard C++ Library <regex> template class?  Well, apparently, not from a COBOL program.  But, it shouldn’t be too hard to write a C++ CICS program….  No, not too hard.

Leave a Reply

Your email address will not be published. Required fields are marked *