www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Email validation

reply Vino <vino.bheeman hotmail.com> writes:
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
Nov 28 2017
next sibling parent reply Rene Zwanenburg <renezwanenburg gmail.com> writes:
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
Nov 28 2017
parent reply Vino <vino.bheeman hotmail.com> writes:
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
Nov 28 2017
next sibling parent reply Mike Wey <mike-wey example.com> writes:
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
Nov 28 2017
parent codephantom <me noyb.com> writes:
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.
Nov 28 2017
prev sibling parent codephantom <me noyb.com> writes:
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
Nov 28 2017
prev sibling next sibling parent codephantom <me noyb.com> writes:
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"); } // ----------------------
Nov 28 2017
prev sibling parent reply codephantom <me noyb.com> writes:
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"); } // --------------------
Nov 28 2017
parent reply Dmitry <dmitry indiedev.ru> writes:
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.
Nov 28 2017
parent Vino <vino.bheeman hotmail.com> writes:
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
Nov 28 2017