Thread overview
Email validation
Nov 28, 2017
Vino
Nov 28, 2017
Rene Zwanenburg
Nov 28, 2017
Vino
Nov 28, 2017
Mike Wey
Nov 29, 2017
codephantom
Nov 28, 2017
codephantom
Nov 29, 2017
codephantom
Nov 29, 2017
codephantom
Nov 29, 2017
Dmitry
Nov 29, 2017
Vino
November 28, 2017
Hi All,

 Can you please provide me some example on who to validate an email address as the document dose not have an example for the same

Ex: vino.bheeman@hotmail.com

Conditions :

The domain should contain only "hotmail.com"
The email address should contain the symbol "@"

From,
Vino.B
November 28, 2017
On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:
> Hi All,

You can do this easily using the std.net.isemail module:

https://dlang.org/phobos/std_net_isemail.html

November 28, 2017
On Tuesday, 28 November 2017 at 18:51:50 UTC, Rene Zwanenburg wrote:
> On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:
>> Hi All,
>
> You can do this easily using the std.net.isemail module:
>
> https://dlang.org/phobos/std_net_isemail.html

Hi Rene,

 Can you provide me a example, as the link does not have any examples.

From,
Vino.B
November 28, 2017
On 28-11-17 20:32, Vino wrote:
> On Tuesday, 28 November 2017 at 18:51:50 UTC, Rene Zwanenburg wrote:
>> On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:
>>> Hi All,
>>
>> You can do this easily using the std.net.isemail module:
>>
>> https://dlang.org/phobos/std_net_isemail.html
> 
> Hi Rene,
> 
>   Can you provide me a example, as the link does not have any examples.
> 
> From,
> Vino.B

isEmail returns a struct with the status of the check.
You can use the valid and domainPart to check if it's a valid email address for the hotmail domain.

isMail only checks the formatting of the email address and optionally if the domain has a MX record.


```
auto e = isEmail("vino.bheeman@hotmail.com");

if ( e.valid && e.domainPart == "hotmail.com" )
	...
```

-- 
Mike Wey
November 28, 2017
On Tuesday, 28 November 2017 at 19:32:40 UTC, Vino wrote:
>
>  Can you provide me a example, as the link does not have any examples.
>
> From,
> Vino.B

btw... yes documentation is an acknowledged issue with regards to phobos...but..that aside...it can also be useful (and wise) to look at the unit tests in the source code.

I'm not sure that simply calling something you don't know anything about is such a good idea these days ;-)

...fortunately, we have access to the source - which gets installed with dmd.

or you can find it on github.

https://github.com/dlang/phobos


November 29, 2017
On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:
> Hi All,
>
>  Can you please provide me some example on who to validate an email address as the document dose not have an example for the same
>
> Ex: vino.bheeman@hotmail.com
>
> Conditions :
>
> The domain should contain only "hotmail.com"
> The email address should contain the symbol "@"
>
> From,
> Vino.B

test/improve it yourself. but you get the idea....

// ----------------------

module test;

import std.stdio;
import std.algorithm;

/+
CONDITIONS:
    - The domain should contain only "hotmail.com"
    - The email address should contain the symbol "@"
+/

void main()
{
    string domainRequired = "hotmail.com";

    string emailAddress = "vino.bheeman@hotmail.com";

    auto checkDomain = findSplitAfter(emailAddress, "@"); // requires import std.algorithm

    //writeln(checkDomain); // Tuple!(string, string)("vino.bheeman@", "hotmail.com")

    if (checkDomain[1] == domainRequired)
        writeln("domain ok");
    else
        writeln("invalid domain");


}

// ----------------------

November 29, 2017
On Tuesday, 28 November 2017 at 22:42:27 UTC, Mike Wey wrote:
> isMail only checks the formatting of the email address and optionally if the domain has a MX record.
>

I don't believe MX validation (checkDns) is implemented yet.

November 29, 2017
On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:
> Hi All,
>
>  Can you please provide me some example on who to validate an email address as the document dose not have an example for the same
>
> Ex: vino.bheeman@hotmail.com
>
> Conditions :
>
> The domain should contain only "hotmail.com"
> The email address should contain the symbol "@"
>
> From,
> Vino.B


Here's another nice option I just found.

Interestingly, I had to disable Avast antivirus, otherwise when I compile it, Avast thinks the exectuable is 'suspicous' and prevents any further access to it...wtf?

// ---------------------
module test;

import std.stdio;
import std.algorithm;

/+
CONDITIONS:
    - The domain should contain only "hotmail.com"
    - The email address should contain the symbol "@"
+/

void main()
{
    string domainRequired = "@hotmail.com";

    string emailAddress = "vino.bheeman@hotmail.com";

    emailAddress.endsWith(domainRequired) ? writeln("domain ok")
         : writeln("invalid domain");

}

// --------------------

November 29, 2017
On Wednesday, 29 November 2017 at 03:49:56 UTC, codephantom wrote:
>     string domainRequired = "@hotmail.com";
>
>     string emailAddress = "vino.bheeman@hotmail.com";
>
>     emailAddress.endsWith(domainRequired) ? writeln("domain ok")
>          : writeln("invalid domain");
Also you need check that only one @ used.
November 29, 2017
On Wednesday, 29 November 2017 at 05:22:34 UTC, Dmitry wrote:
> On Wednesday, 29 November 2017 at 03:49:56 UTC, codephantom wrote:
>>     string domainRequired = "@hotmail.com";
>>
>>     string emailAddress = "vino.bheeman@hotmail.com";
>>
>>     emailAddress.endsWith(domainRequired) ? writeln("domain ok")
>>          : writeln("invalid domain");
> Also you need check that only one @ used.

Hi All,

 Thank you, the above code worked.

From,
Vino.B