using System; using System.Globalization; using System.Text.RegularExpressions; using UnityEngine; public class RegexUtilities { bool invalid = false; public bool IsValidEmail(string strIn) { invalid = false; if (String.IsNullOrEmpty(strIn)) return false; // Use IdnMapping class to convert Unicode domain names. try { strIn = Regex.Replace(strIn, @"(@)(.+)$", this.DomainMapper, RegexOptions.None); } catch (RegexMatchTimeoutException) { return false; } if (invalid) return false; // Return true if strIn is in valid e-mail format. try { return Regex.IsMatch(strIn, @"^(?("")("".+?(?= 8) { // Debug.Log(number); return true; } return false; break; case LoginManager.StateCountryTelephoneCode.Ukraine: ar = Phone.ToCharArray(); //if (ar[0].ToString() == "0" && ar[1].ToString() == "7") { //if (ar[2].ToString() == "0" || ar[2].ToString() == "2" // || ar[2].ToString() == "3" || ar[2].ToString() == "6" || ar[2].ToString() == "9") { for (int i = 0; i < ar.Length; i++) { if (Char.IsDigit(ar[i])) { number += ar[i]; } } } } if (number.ToCharArray().Length == 10) { // Debug.Log(number); return true; } return false; break; case LoginManager.StateCountryTelephoneCode.Iceland: ar = Phone.ToCharArray(); //if (ar[0].ToString() == "0" && ar[1].ToString() == "7") { //if (ar[2].ToString() == "0" || ar[2].ToString() == "2" // || ar[2].ToString() == "3" || ar[2].ToString() == "6" || ar[2].ToString() == "9") { for (int i = 0; i < ar.Length; i++) { if (Char.IsDigit(ar[i])) { number += ar[i]; } } } } if (number.ToCharArray().Length == 7) { // Debug.Log(number); return true; } return false; break; } } catch (Exception) { throw; } return false; } /* public bool IsValidNumberPhone(string strIn) { invalid = false; if (String.IsNullOrEmpty(strIn)) return false; if (invalid) return false; // Return true if strIn is in valid phone number format. try { Debug.Log(Regex.IsMatch(strIn, @"^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$", RegexOptions.IgnoreCase)); return Regex.IsMatch(strIn, @"^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$", RegexOptions.IgnoreCase); } catch (RegexMatchTimeoutException) { return false; } }*/ private string DomainMapper(Match match) { // IdnMapping class with default property values. IdnMapping idn = new IdnMapping(); string domainName = match.Groups[2].Value; try { domainName = idn.GetAscii(domainName); } catch (ArgumentException) { invalid = true; } return match.Groups[1].Value + domainName; } } public class RegexMatchTimeoutException : Exception { }