Merge pull request #309 from aubrey-b/email-check

Check for a valid email.
This commit is contained in:
Shaun Walker 2020-03-30 14:41:38 -04:00 committed by GitHub
commit 974b8877dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -42,13 +42,15 @@
string _confirm = ""; string _confirm = "";
string _email = ""; string _email = "";
string _displayName = ""; string _displayName = "";
bool _isEmailValid = false;
private async Task Register() private async Task Register()
{ {
try try
{ {
_message = ""; _message = "";
if (_username != "" && _password != "" && _confirm != "" && _email != "") _isEmailValid = Utilities.IsValidEmail(_email);
if (_username != "" && _password != "" && _confirm != "" && _isEmailValid)
{ {
if (_password == _confirm) if (_password == _confirm)
{ {

View File

@ -1,5 +1,7 @@
using System.Globalization; using System;
using System.Globalization;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
namespace Oqtane.Shared namespace Oqtane.Shared
{ {
@ -217,5 +219,15 @@ namespace Oqtane.Shared
return ""; return "";
} }
} }
public static bool IsValidEmail(string email)
{
if (string.IsNullOrEmpty(email)) return false;
return Regex.IsMatch(email,
@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));
}
} }
} }