Page 1 of 1

how to check email and website entered

Posted: July 17th, 2014, 3:00 pm
by ikwamena
Please members get me codes for my data entry to check email and website entered is correct else display an error message.

Re: how to check email and website entered

Posted: July 28th, 2014, 10:33 am
by Gregory Martin
Some tasks like this might be easier if CSPro had a way to evaluate regular expressions, but such functionality doesn't exist in the current version of CSPro. You could write logic to evaluate email addresses. This might allow some invalid email addresses through, but it would work for 99% of email addresses (except that it doesn't evaluate the final domain). Here is sample logic for the email address:
PROC EMAIL

    
numeric isValid = 1;

    
numeric atPos1 = pos("@",EMAIL);
    
numeric atPos2 = pos("@",EMAIL[atPos1 + 1]);

    
if atPos1 = 0 or atPos2 > 0 then // there must be only one @
        isValid = 0;
    
    
elseif atPos1 < 2 or ( length(strip(EMAIL)) - atPos1 ) = 0 then // there must be at least one character on both sides of the @
        isValid = 0;
    
    
elseif pos(".",EMAIL[atPos1 + 1]) = 0 then // there must be a . after the @
        isValid = 0;
    
    
else
        
numeric ctr;
        
        
do ctr = 1 while ctr <= length(strip(EMAIL)) and isValid
        
            
if ctr <> atPos1 and poschar("ABCDEFGHIJKLMNOPQRSTUVWXYZ.",toupper(EMAIL[ctr:1])) = 0 then
                isValid =
0;
            
endif;      
        
        
enddo;
    
    
endif;
    
    
if not isValid then
        
errmsg("Error in the email address: %s",strip(EMAIL));
        
reenter;
    
endif;