Validity Check

475 pts.
Tags:
CMD
CMD Source
I have a CMD that prompts for an email address, subject, message, and spool file info. Is there a way to validate the email prompt field in my CL to determine if the user keyed in the '@' symbol and '.' for the address?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Short of writing your own code for the validation, don’t know if there is an automtic one.

Write something similar to code below and link to command processing program.

C ‘@’ SCAN #EMAIL:2 X 30 80
C *IN80 IFEQ *ON
C ‘.’ SCAN #EMAIL:2 X 81
C *IN81 IFEQ *OFF
C SETON 90
C ENDIF
C ELSE
C SETON 90
C ENDIF

============================================================

Here’s an ILE CL module that verifies (1) that an @ sign is included, (2) that the @ is not in the first position and (3) that at least one “.” comes after the @ sign. Compile the module and create the program as:<pre>
CRTPGM PGM( mylib/mypgm )
BNDDIR(QC2LE)
ACTGRP(*CALLER)</pre>
The program code:<pre>
pgm ( +
&pEMA +
)

dcl &pEMA *char 256

dcl &EMA *char 257
dcl &c *char 2
dcl &x00 *char 1 value( x’00′ )

dcl &lEMA *dec ( 5 0 ) value( 0 )

dcl &atPos *int value( 0 )
dcl &dotPos *int value( 0 )
dcl &chkPos *int value( 0 )

/* Find length of e-mail address text… */

rtvmsg CPF9897 msgf( QSYS/QCPFMSG ) +
msgdta( &pEMA ) msglen( &lEMA )

/* Set null-terminated work variables… */

chgvar &EMA ( &pEMA *tcat &x00 )
chgvar &c ( ‘@’ *cat &x00 )

/* Locate an “@”… */

callprc ‘strcspn’ ( +
&EMA +
&c +
) +
rtnval( &atPos )

/* Change ‘index’ value to ‘position’ value… */
chgvar &atPos ( &atPos + 1 )

/* Check if “@” not found or at beginning… */

if ( &lEMA *le &atPos *or &atPos *eq 1 ) do
sndpgmmsg msgid( CPD0006 ) msgf( QSYS/QCPFMSG ) +
msgdta( ’0000 No “@” or initial “@” found.’ ) +
msgtype( *DIAG )
sndpgmmsg msgid( CPF0002 ) msgf( QSYS/QCPFMSG ) msgtype( *ESCAPE )
return
enddo

/* Set for finding dots… */
chgvar &c ( ‘.’ *cat &x00 )

/* Loop to find final dot… */
/* We capture &dotPos at the top to save the value of the +
previous loop’s position. The final loop will not find a dot. */

dountil ( &dotPos *ge &lEMA )

chgvar &chkPos &dotPos
callprc ‘strcspn’ ( +
&EMA +
&c +
) +
rtnval( &dotPos )
chgvar &dotPos ( &dotPos + 1 )

/* Replace found dots with blank — don’t find again… */
if ( &dotPos *lt &lEMA ) +
chgvar %sst( &EMA &dotPos 1 ) ‘ ‘

enddo

/* Check if last dot not after “@”… */

if ( &chkPos *le &atPos ) do
sndpgmmsg msgid( CPD0006 ) msgf( QSYS/QCPFMSG ) +
msgdta( ’0000 No dot (“.”) after “@”.’ ) +
msgtype( *DIAG )
sndpgmmsg msgid( CPF0002 ) msgf( QSYS/QCPFMSG ) msgtype( *ESCAPE )
return
enddo

return

endpgm</pre>
More logic can be added, e.g., to verify that there’s at least one character between the “@” and the “.” and that the “.” isn’t the last character.

In any case, it is a working validity-checker program. As coded, it works for a command that has a single parameter — an e-mail address that’s 256 bytes maximum.

Tom

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following