question

Dale Strickler avatar image
Dale Strickler asked

What is a valid email?

I am using this C# code to validate a new player email before passing it to PlayFabClientAPI.RegisterPlayFabUser(RegisterPlayFabRequest, OnRegisterSuccess, ErrorOccured);:

try
{
    var m = new MailAddress(_email);
    BaaS.Email = _email;
}
catch (Exception e)
{
    // Complain about email.
}

I found that an email of the form "Name@domain" (not .anything) passes the .NET test. But it fails when submitted to PlayFab. I found this article: https://stackoverflow.com/questions/1365407/c-sharp-code-to-validate-email-address where the most upvoted answer has this note:

Note that e-mail addresses are more forgiving than you might first assume. These are all perfectly valid forms:

  • cog@wheel
  • "cogwheel the orange"@example.com
  • 123@$.xyz

This means that .NET will accept emails that PlayFab will not. This leads me to wonder two things:

  1. Should I not check and just parse the return from PlayFab to report the error? This seems like a service call that could be avoided by a local validation.
  2. If I am going to validate locally what code does PlayFab use to establish if something is a valid email?
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

>> Should I not check and just parse the return from PlayFab to report the error? This seems like a service call that could be avoided by a local validation. If I am going to validate locally what code does PlayFab use to establish if something is a valid email?

PlayFab defined an Email Regex which not 100% matches .net MailAddress to validate the email addresses. But MailAddress still can filter a part of invalid emails. Currently, you can combine them to do email validation twice to avoid a part of invalid requests. Besides, you can try to add a feature request to add the description of valid email format in the official documents.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.