private bool InputIsInvalid(string input) { if (input.Length > Ean13.CheckedLength) { return(true); } if (input.Length == Ean13.CheckedLength && !Ean13.Check(input)) { return(true); } return(input.ToCharArray().Any(_ => !char.IsDigit(_))); }
private void OnTextChanged(object sender, TextChangedEventArgs e) { if (string.IsNullOrEmpty(e.NewTextValue)) { return; } if (e.NewTextValue.Length > Ean13.CheckedLength || e.NewTextValue.Length == Ean13.CheckedLength && !Ean13.Check(e.NewTextValue)) { AssociatedObject.Text = e.OldTextValue; return; } if (e.NewTextValue.Length != Ean13.CheckedLength) { return; } Command?.Execute(e.NewTextValue); }