Skip to content

Commit

Permalink
Emails are no longer accepeted in the username field
Browse files Browse the repository at this point in the history
  • Loading branch information
robhillman97 committed Oct 18, 2023
1 parent 160ce9e commit 803a3e4
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions Assets/MirageXR/Tests/NewUI/LoginView_v2.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using MirageXR;
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MirageXR;
using UnityEngine;
using UnityEngine.UI;

Expand Down Expand Up @@ -159,7 +159,26 @@ private static bool IsValidUsername(string value)
{
const string regexExpression = "^\\S{3,}$";
var regex = new Regex(regexExpression);
return regex.IsMatch(value);
var isValid = regex.IsMatch(value);

const string MatchEmailPattern =
@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

regex = new Regex(MatchEmailPattern);

var isEmail = regex.IsMatch(value);

if (isEmail || !isValid)
{
return false;
}
else
{
return true;
}
}

private static bool IsValidPassword(string value)
Expand All @@ -168,4 +187,24 @@ private static bool IsValidPassword(string value)
var regex = new Regex(regexExpression);
return regex.IsMatch(value);
}

private static bool IsAnEmail(string email)
{
const string MatchEmailPattern =
@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
+ @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
+ @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
+ @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

var regex = new Regex(MatchEmailPattern);

if (email != null)
{
return regex.IsMatch(email);
}
else
{
return false;
}
}
}

0 comments on commit 803a3e4

Please sign in to comment.