Skip to main content
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Uniface Development: Email address validation

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

19 replies

Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

Hi all, I am probably a little late. As mentioned by some of you, this is exactly what are regular expressions for. We have a universal approach to such kind of requests called LXScript : Instead of focusing on specific topics (like creating an excel files through intermediate steps) we make the necessary technology directly available to Uniface by extending it.  The extension is bidirectional and opens completely new possibilities to Uniface developers : regular expression, reading from/writing to real Excel files (including formating, charts, …), easy to write webservices, all kind of networking, image processing, graphic rendering, real xml processing, encrypting  ….  those fancy things that are difficult to achieve with Uniface alone.  And all this in an intuitive way and fully embedded in the Uniface runtime environment, not like a spawn shell/bat command limited to one OS. With LXScript regular expressions can be used within Uniface in just a single line of code, and regexp is just one of the many things that you will get with LXScript. You may google for labsolution and LXScript to get more information. Feel free to contact me for more information ! Best regards gerd


Author: gerd (gerd.vassen@labsolution.lu)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

Try using RegX for... Email Validation Lee


Author: creiglee (creiglee@yahoo.com)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

This is my attempt. My code is a bit longer but easier to understand for myself.
Either regex or some enhancements to syntax strings would but nice to have in Uniface.

 

Operation Checkmail
params
    String vMail : In
    String vError : Out
endparams
variables
    string vLocalPart, vDomain
    numeric vStatus
endvariables
 
    ; First we split the string in the part before and the part after @
    vStatus = $split(vMail, 1, "@", vLocalPart, vDomain)
    if (vStatus = 0)
        vError = "Error in email adress: No @ found."
    else
        ; Decompose part before @ into sub-parts.
        call CheckDots(vLocalPart,"LOCAL",vError)
        if (vError = "")
            ; Decompose part after @ into sub-parts.
            call CheckDots(vDomain,"DOMAIN",vError)
        endif
    endif
 
    if (VError = "")
        return(0)
    else
        return(-1)
    endif
end
 
;----------------------------------------------------
Entry CheckDots
params
    string vPart   : In
    string vType   : In
    string vError : Out
endparams
variables
    numeric vStatus, vPart1, vPart2
endvariables
 
    if (vType = "DOMAIN" & $scan(vPart,".") = 0)
        vError = "Error in email adress: no . in domain"
    else
        repeat
            vStatus = $split(vPart, 1, ".", vPart1, vPart2)
 
            ; $status = 0 Means no more . found, stop
            ; $status = 1 Means . at the start, give error
            ; vPart2 = "" Means no characters after . , give error
 
            selectcase vStatus
            case 0
               call CheckWord(vPart,vType,vError)
            case 1
               vError = "Error in email adress: Incorrect ."
            elsecase
               if (vPart2 = "")
                   vError = "Error in email adress: Incorrect ."
               else
                   vPart = vPart2
                   call CheckWord(vPart1,vType,vError)
               endif
            endselectcase
        until (vStatus=0 | vError <> "")
    endif
end
 
;----------------------------------------------------
Entry CheckWord
params
    string vWord   : In
    string vType   : In
    string vError : Out
endparams
variables
    string vValid
endvariables
 
    ; parts before and after @ have diffent valid characters
    if (vType = "LOCAL")
        vValid = "!#$%%%%&’*+-0123456789=?ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~"
    else
        vValid = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    endif
       
    while (vWord <> "")
        if ($scan(vValid, vWord[1:1]) > 0)
            vWord = vWord[2]
            if ($length(vWord) = 1 & vWord = "-" & vType = "DOMAIN")
               vError = "Error in email address: Invalid character %%vWord[1:1]%%%"
               vWord = ""
            endif             
        else
            vError = "Error in email address: Invalid character %%vWord[1:1]%%%"
            vWord = ""
        endif
    endwhile
end
 
 

Author: Theo Neeskens (tneeskens@itblockz.nl)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

Hi Theo,

maybe it was lost during transfer of data, that in my example, the real email-address was included in "<" angle-braces.

This is the format you will get from a lot of email programs if you use cut and paste or process emails (using UPOPMAIL).

On the IP Address issue:

It was not about your collection of rules, but on otheres expressed in this thread about checking the TLD (toplevel domain like .com)

Success, Uli


Author: ulrich-merkel (ulrichmerkel@web.de)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

Hi disco,

it depends what you consider a valid email adress:

If we start from:

has to have a "@"
something in front of the "@"
and the text after the "@" has to have at least one "."

a syntax string will do.

 

For more sophisticated tests you can use the <VLDF> trigger:

split the email adress at the "@"
examine both parts separately.

Success, Uli


Author: ulrich-merkel (ulrichmerkel@web.de)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

Hi discooptus,

I do not have any way to validate e-mail address nativly in Uniface and I consider this to be one of quite big issues. Uniface has some validation, via syntax etc, but this is all far too limited. See my wish of implementing regular expression in Uniface. Using this, it should be quite easy to validate many things, including e-mail addresses, phone numbers, postal codes etc. Of course, regular expressions can be used for many other things.

Kind regards,
Zdenek Socha


Author: sochaz (zdenek.socha@fullsys.cz)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

Uli said:
To make it worse, even an IP-address is allowed in the domain part
anyone@127.12.100.5
and my valid email address may look like:
"Ulrich Merkel" ulrichmerkel@web.de

The ip adress is not a problem as it fits within the validation rules that I found.


The email adress with the quoted string might be acceptable for a mailserver,
but we are looking at DATA ENTRY VALIDATION.
I don't think many Uniface application have the need for data entered in this format.
That is why I ignored the whole quoted string option in the specs.
You send it TO a mail server in this format by combining name and email data from your application.


Author: Theo Neeskens (tneeskens@itblockz.nl)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

Hi Theo,

just spent some 2 hrs browsing the web for "the" eMail-Address validation.
The collection can be found on the "giveaways" page of www.uli-merkel.de/dito

To make it worse, even an IP-address is allowed in the domain part
anyone@127.12.100.5
and my valid email address may look like:
"Ulrich Merkel" <ulrichmerkel@web.de>

So I recommend when we create an eMail Validation Routine
we start with a specification  WHAT WE SEE as a valid one (as you have done in your post)

With all the new domain features (umlauts, numbers only, 2chars only) we can not cover all situations.
But we can learn and add these in the course of the time.

The important bit (as you see on my 30 lines above) is to get the coding started
and be open for changes.

Success, Uli


Author: ulrich-merkel (ulrichmerkel@web.de)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

The spec's that I found on the Internet were a bit difficult to understand.
I have tried to write them down in a simpler form.

An email adress is: Local-part@Domain

Local-part:
One or more Words separated by periods.
NB: So no period at the start or end of Local-part.
A Word can be an Atom or a Quoted String.
Quoted String is not relevant for our purpose.
 
Domain:
Two or more Sub-domains separated by periods.
NB: So no period at the start or end of Domain.
A Sub-domain can be an Atom (a.k.a. Domain-ref) or a Quoted String (a.k.a. Domain-literal)
Quoted String is not relevant for our purpose.

Atom:
An Atom is one or more chars in the range #33..#126 except ()<>@,;:\\/".[]
That leaves us with:
! # $ % & ’ * + - 0 1 2 3 4 5 6 7 8 9 = ? A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

Special considerations:
In a Sub-domain Atoms are further restricted to letters (upper and lowercase, digits and hyphens. A Sub-domain cannot end with an hyphen.

This are the syntax requirements. I'll try to code this first.
After that we can worry about symantical requirements, like what should be the contect of sub-domains (.com, .org. .country etc)
And finally a check on the actual existense of the email adress.

Please post your comments if you think these specs are wrong!


Author: Theo Neeskens (tneeskens@itblockz.nl)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:17 AM UTC

Email address validation

Author: disco@discooctopus.com (discooctopus)

Hi,

Does anyone have a nice way of validating an email address (syntax string, proc code, field syntax properties, etc) in a field with a stringent set of rules?

I did find this... http://uniface.communityzero.com/uniface?go=2222502&content=entry ... but not sure if this type of thing will be considered???

Thanks

 

Hi Theo,

from my point of view, rules are as follows:

  • string with 2 parts, separated by at-sign (@), let's call them username and domain, so it looks like this username@domain
  • username is up to 64characters long, made of these characters: lowercase and uppercase english letters (a-z, A-Z), digits (0-9), dot (.) , underscore (_), hypen (-), plus (+), the first and the last one can't be dot (it's always better the first and the last char to be a letter or digit)
  • domain should be up to cca 255 characters, better to keep it under 100 chars long, made of 2 parts separated by dot (.), first part (let's call it local domain) is made of lowercase english letters (a-z), digits (0-9), hyper(-), up to 100chars long, the secont part (let's call it top domain) is from 2 to 4 characters long made of lowercase english letters (a-z)

It is not perfect, nor it match RFC standard, but I believe, it is strong enough to reduce user typo's in entering email adress.

As for me, it woud be great to be able to do this validation using some kind of syntax, like Uniface syntax string. Or, suggested by me, regexp. In that case, it would be very easy, to define field syntax (using syntax string or regexp) to nativly validate the field with single email adress. Or in proc code, one could use something like this:

 if (EMAIL.DUMMY != $regexp("^[a-zA-Z0-9_.+-]{2,64}@[a-z0-9-]{5,100}\\.[a-z]{2,4}$"))
  message "Invalid email adress!"
endif

Of course, having a field with more than one e-mail adress, there could be a cycle (split data using space characters - another regexp, since it can be space, coma, tab etc..). And one could split the string with function like $regexp_split(...) that would split it to subparts, if you need. Or, you could of course make a list of adresses with $regexp_replace(FIELD.DUMMY, 1, $regexp("\\s"), ";", -1) where ";" is item separator (that is gold ;). I know, this is more then simple validation, but I can't resist to mention it here.

All in all, you could define field in your model entity like string field, VC255, field syntax REGEXP("^[a-zA-Z0-9_.+-]{2,64}@[a-z0-9-]{5,100}\\.[a-z]{2,4}$") - this would be just perfect. I can't think of any Uniface syntax string doing this job (so we could enter it as field syntax).

Kind regards
Zdenek


Author: sochaz (zdenek.socha@fullsys.cz)