Ejemplo n.º 1
0
        private void ExpiryDate_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            char c = Convert.ToChar(e.Text);

            if (Char.IsControl(c))
            {
                CardHolderName.Focus();
                return;
            }
            int a = ExpiryDate.Text.ToCharArray().Where(f => Char.IsDigit(f)).Count();

            if (Char.IsSurrogate(c) || Char.IsDigit(c) && a <= 3)
            {
                if (a % 2 == 0 && a != 0)
                {
                    ExpiryDate.Text          += "/";
                    ExpiryDate.SelectionStart = ExpiryDate.Text.Length;
                    CardHolderName.Focus();
                    ExpiryDate.Focus();
                }
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }
Ejemplo n.º 2
0
        private void CardNumber_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            char c = Convert.ToChar(e.Text);

            if (Char.IsControl(c))
            {
                ExpiryDate.Focus();
                return;
            }
            int a = CardNumber.Text.ToCharArray().Where(f => f != ' ').Count();

            if (Char.IsDigit(c) && a <= 15)
            {
                if (a % 4 == 0 && a != 0)
                {
                    CardNumber.Text          += " ";
                    CardNumber.SelectionStart = CardNumber.Text.Length;
                    CardHolderName.Focus();
                    CardNumber.Focus();
                }
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }