protected override string IllegalCharFilter(IEntryValidationBehavior behavior, string newText, string originalText, out bool isOutsideOfRange) { return(PhoneNumberIllegalCharFunc(base.IllegalCharFilter(behavior, newText, originalText, out isOutsideOfRange), out isOutsideOfRange)); }
/// <remarks> /// We can only evaluate the unmasked text (otherwise all of our tests fail). /// </remarks> protected override string IllegalCharFilter(IEntryValidationBehavior behavior, string newText, string originalText, out bool isOutsideOfRange) { isOutsideOfRange = false; // CRITICAL var strippedNewText = StripMaskFromText(newText); var strippedOldText = StripMaskFromText(originalText); if (strippedNewText.IsEmpty() || strippedNewText.IsSameAs(strippedOldText)) { return(newText); } // Spaces are illegal if (strippedNewText.IsNotEmpty() && strippedNewText.Contains(FormsConst.SPACE)) { // FAIL return(originalText); } // The new text is not empty and has changed if (StringFormat.IsEmpty()) { // If the base rejects, allow that to have control // Do not send in stripped values; the base evaluates the mask as well as the net entry. var testString = base.IllegalCharFilter(behavior, newText, originalText, out var itOutsideOfRange); if (testString.IsSameAs(originalText)) { // Probably failed the length test return(originalText); } } // Consider illegal min and max values if (MaxDecimalNumber.IsLessThanOrEqualTo(MinDecimalNumber)) { Debug.WriteLine(nameof(NumericEntryValidationBehavior) + ": " + nameof(IllegalCharFilter) + ": Max number is less than or equal to min number!!!"); return(originalText); } // Numbers are either: // * "Whole" (no special symbols allowed) or // * "Decimal" (a single dot is allowed, plus a certain number of characters after that). switch (ValidationType) { case ValidationTypes.DecimalNumber: if (!double.TryParse(strippedNewText, out var testDouble)) { return(originalText); } isOutsideOfRange = !testDouble.IsGreaterThanOrEqualTo(MinDecimalNumber) || !testDouble.IsLessThanOrEqualTo(MaxDecimalNumber); // ... else watch out for excessive decimal characters var decimalPos = strippedNewText.PositionOfDecimal(); if (decimalPos > 0) { var newTextCharsToRightOfDecimal = strippedNewText.Length - 1 - decimalPos; if (newTextCharsToRightOfDecimal > CharsToRightOfDecimal) { return(originalText); } // ELSE fall through and return the new text. } // ELSE fall through and return the new text. break; case ValidationTypes.WholeNumber: if (!long.TryParse(strippedNewText, out var testLong)) { return(originalText); } // Does not apply to whole numbers isOutsideOfRange = false; // ELSE fall through and return the new text. break; default: // This is a text field with numeric constraints // Illegal Debug.WriteLine(nameof(NumericEntryValidationBehavior) + ": " + nameof(PrepareTextForEditing) + ": illegal numeric validation type ->" + ValidationType + "<-"); break; } return(newText); }
protected override bool IsWholeEntryValid(IEntryValidationBehavior behavior, string currentText) { return(base.IsWholeEntryValid(behavior, currentText) && ValidateCompareEntry(behavior, currentText)); }
/// <summary> /// Determines whether [is whole entry valid] [the specified behavior]. /// </summary> /// <param name="behavior">The behavior.</param> /// <param name="currentText">The current text.</param> /// <returns><c>true</c> if [is whole entry valid] [the specified behavior]; otherwise, <c>false</c>.</returns> protected override bool IsWholeEntryValid(IEntryValidationBehavior behavior, string currentText) { if (!base.IsWholeEntryValid(behavior, currentText)) { return(false); } if (currentText.IsEmpty()) { IssueMinLengthValidationError(); return(false); } var capitalCharacterCount = currentText.Count(char.IsUpper); var lowCaseCharacterCount = currentText.Count(char.IsLower); var characterCount = currentText.Count(); var numericCharacterCount = currentText.Count(char.IsNumber); var hasRepeatedChars = !currentText.DoesNotRepeatCharacters(MaxRepeatChars); var specialCharacterCount = currentText.Length - capitalCharacterCount - lowCaseCharacterCount - numericCharacterCount; if (characterCount < MinCharacterCount) { IssueMinLengthValidationError(); return(false); } // Max characters is restricted inside the entry validator if (characterCount < MinCharacterCount) { IssueMinLengthValidationError(); return(false); } if (capitalCharacterCount < MinCapitalCharacterCount) { IssueValidationError(MinCapitalCharacterCount + " total capital character(s)."); return(false); } if (lowCaseCharacterCount < MinLowCaseCharacterCount) { IssueValidationError(MinLowCaseCharacterCount + " total lower-case character(s)."); return(false); } if (numericCharacterCount < MinNumericCharacterCount) { IssueValidationError(MinNumericCharacterCount + " total numeric character(s)."); return(false); } if (specialCharacterCount < MinSpecialCharacterCount) { IssueValidationError(MinSpecialCharacterCount + " total special character(s)."); return(false); } if (hasRepeatedChars) { LastValidationError = "The password should not have more than " + MaxRepeatChars + " adjacent character(s)"; return(false); } ClearValidationError(); return(true); }