Exemplo n.º 1
0
 /// <summary>
 /// Sets initial value from code behind. If isRequired is true, user needs to change the value before saving is possible.
 /// If isRequired is null, IsRequired will not be changed.
 /// </summary>
 public override void Initialise(string?text = null, bool?isRequired = false)
 {
     if (!string.IsNullOrEmpty(text) && !EmailValidator.IsValidEmail(text))
     {
         throw new Exception($"Error EmailTextBox.Initialise(): '{text}' is not a valid email address).");
     }
     base.Initialise(text, isRequired);
 }
Exemplo n.º 2
0
        //      --------------

        protected override void OnTextBoxInitialized()
        {
            //verify the values set in XAML
            if (Text.Length > 0 && !EmailValidator.IsValidEmail(Text))
            {
                throw new Exception($"Error EmailTextBox: '{Text}' is not a valid email address).");
            }
        }
Exemplo n.º 3
0
        public void TestEmailAdr()
        {
            //default settings, must be reapplied because another test might have changed them
            EmailValidator.SetAsciiSpecialCharsDefault();
            EmailValidator.IsBlankAllowed = false;
            EmailValidator.IsInternationalCharSetAllowed = false;
            Assert.IsFalse(EmailValidator.IsValidEmail(""));
            Assert.IsFalse(EmailValidator.IsValidEmail("@"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a@"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a@b"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a@b."));
            Assert.IsFalse(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("@b.cd"));
            Assert.IsFalse(EmailValidator.IsValidEmail("ab.cd@"));
            Assert.IsFalse(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail(new string('a', 64) + "@" + "a." + new string('a', 255 - 2)));
            Assert.IsFalse(EmailValidator.IsValidEmail(new string('a', 64) + "@" + "a." + new string('a', 256 - 2)));
            Assert.IsFalse(EmailValidator.IsValidEmail(new string('a', 65) + "@" + "a." + new string('a', 255 - 2)));
            Assert.IsFalse(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a#[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a&[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a'*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a*[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a/[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a^[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a`[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a{[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a|[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a}[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a\"*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a([email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a)[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a,[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a:[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a;[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a<*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a>[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a[[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a\\[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a][email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("\"a Z\"@b.cd"));
            Assert.IsFalse(EmailValidator.IsValidEmail("ABC@[192.168.0.1]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("ABC@[IPv6:2001:db8:1ff::a0b:dbd0]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("试.یشی@XN--0ZWM56D.XN--HGBK6AJ7F53BBA"));

            EmailValidator.SetExtendedAsciiSpecialChars();
            Assert.IsFalse(EmailValidator.IsValidEmail(""));
            Assert.IsFalse(EmailValidator.IsValidEmail("@"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a@"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a@b"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a@b."));
            Assert.IsFalse(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("@b.cd"));
            Assert.IsFalse(EmailValidator.IsValidEmail("ab.cd@"));
            Assert.IsFalse(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail(new string('a', 64) + "@" + "a." + new string('a', 255 - 2)));
            Assert.IsFalse(EmailValidator.IsValidEmail(new string('a', 64) + "@" + "a." + new string('a', 256 - 2)));
            Assert.IsFalse(EmailValidator.IsValidEmail(new string('a', 65) + "@" + "a." + new string('a', 255 - 2)));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a#[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a&[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a'*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a*[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a/[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a^[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a`[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a{[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a|[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a}[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a\"*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a([email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a)[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a,[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a:[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a;[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a<*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a>[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a[[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a\\[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a][email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("\"a Z\"@b.cd"));
            Assert.IsFalse(EmailValidator.IsValidEmail("ABC@[192.168.0.1]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("ABC@[IPv6:2001:db8:1ff::a0b:dbd0]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("试.یشی@XN--0ZWM56D.XN--HGBK6AJ7F53BBA"));

            EmailValidator.SetExtendedQuotedAsciiSpecialChars();
            EmailValidator.IsBlankAllowed = true;
            Assert.IsFalse(EmailValidator.IsValidEmail(""));
            Assert.IsFalse(EmailValidator.IsValidEmail("@"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a@"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a@b"));
            Assert.IsFalse(EmailValidator.IsValidEmail("a@b."));
            Assert.IsFalse(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("@b.cd"));
            Assert.IsFalse(EmailValidator.IsValidEmail("ab.cd@"));
            Assert.IsFalse(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsFalse(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail(new string('a', 64) + "@" + "a." + new string('a', 255 - 2)));
            Assert.IsFalse(EmailValidator.IsValidEmail(new string('a', 64) + "@" + "a." + new string('a', 256 - 2)));
            Assert.IsFalse(EmailValidator.IsValidEmail(new string('a', 65) + "@" + "a." + new string('a', 255 - 2)));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a#[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a&[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a'*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a*[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a/[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a^[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a`[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a{[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a|[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a}[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a\"*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a([email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a)[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a,[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a:[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a;[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a<*****@*****.**"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a>[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a[[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a\\[email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("a][email protected]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("\"a Z\"@b.cd"));
            Assert.IsFalse(EmailValidator.IsValidEmail("ABC@[192.168.0.1]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("ABC@[IPv6:2001:db8:1ff::a0b:dbd0]"));
            Assert.IsTrue(EmailValidator.IsValidEmail("[email protected]"));
            Assert.IsFalse(EmailValidator.IsValidEmail("试.یشی@XN--0ZWM56D.XN--HGBK6AJ7F53BBA"));

            EmailValidator.IsInternationalCharSetAllowed = true;
            Assert.IsTrue(EmailValidator.IsValidEmail("试.یشی@XN--0ZWM56D.XN--HGBK6AJ7F53BBA"));
        }