-
Notifications
You must be signed in to change notification settings - Fork 0
Notification usage
ValidateMe is not only a validation lib. It also has a notification center. When you use any extension method that ValidateMe offers and do not set the first parameter as false, once a validation fails, ValidateMe will generate an error message. There's a default error message for every single validation on it.
Once a validation fails and the message is created. Everytime you need to retrieve the messages, you just need to call
Notification.Get()
Get method will return all error messages generated until the moment it is called. It receives a single parameter called clearAfterGet that will clear the error message stack after return. If you do not want it to clear, just pass false as parameter.
Notification.Get(false)
In any of the cases above, an IReadOnlyList of strings is returned. Each item of the list consists in "Code: Message" structure.
If you do not want to retrive the messages and just know if has occurred any error while validating, you can use Count that will return the number of errors or HasErrors that will return a boolean whether has errors.
By default, ValidateMe has one error message for each validation that fails. But, if you want to change the messages it is possible. You can create your own error messages by generating a JSON file and set it on Error class in its SetPath(string file) static method. Your JSON must be in the following structure:
{
"MessageTitle": "New message"
}
In the following table you can check all messages title, content and code.
Title | Type | Content | Code |
---|---|---|---|
HasNoValue | General | {0} is required | 1001 |
IsNotGreaterThan | String/Numeric | {0} must be greater than {1} {2} | 1002 |
IsNotSmallerThan | String/Numeric | {0} must be smaller than {1} {2} | 1003 |
Misformatted | String | {0} is not well formatted | 1101 |
IsNotAlphabetic | String | {0} must contains only letters | 1102 |
IsNotNumeric | String | {0} must contains only numbers | 1103 |
IsNotAlphanumeric | String | {0} must contains at least one letter and one number | 1104 |
IsNotEmail | String | {0} is not a valid email | 1105 |
IsNotGuid | String | {0} must be in Guid format | 1106 |
IsNotSafe | String | {0} does not match our security patterns | 1107 |
HasNotExactLength | String | {0} must has exactly {1} characters | 1108 |
HasNoSpecialCharacters | String | {0} does not contains any special character | 1109 |
HasNotMinimumWords | String | {0} must contains at least {1} words | 1110 |
IsNotInPast | DateTime | {0} must be in the pas | 1201 |
IsNotInFuture | DateTime | {0} must be in the future | 1202 |
IsNotToday | DateTime | {0} must be today | 1203 |
IsNotYesterday | DateTime | {0} must be yesterday | 1204 |
IsNotTomorrow | DateTime | {0} must be tomorrow | 1205 |
IsNotInLast365Days | DateTime | {0} must be in the last 365 days | 1206 |
IsNotInNext365Days | DateTime | {0} must be in the next 365 days | 1207 |
IsNotDawn | DateTime | {0} must be dawn | 1208 |
IsNotMorning | DateTime | {0} must be morning | 1209 |
IsNotAfternoon | DateTime | {0} must be afternoon | 1210 |
IsNotEvening | Numeric | {0} must be evening | 1211 |
IsNotLeapYear | DateTime | {0} must be a leap year | 1212 |
IsNotMoreRecentThan | DateTime | {0} must be more recent than {1} | 1213 |
IsNotOlderThan | DateTime | {0} must be older than {1 | 1214 |
IsNotWeekday | DateTime | {0} must be weekday | 1215 |
IsNotWeekend | DateTime | {0} must be weekend | 1216 |
HasNotEnoughYears | DateTime | {0} must has at least {1} years until now | 1217 |
HasMoreThanNeededYears | DateTime | {0} must has up to {1} years | 1218 |
HasNotEnoughDays | DateTime | {0} must has at least {1} days until now | 1219 |
HasMoreThanNeededDays | DateTime | {0} must has up to {1} days | 1220 |
IsNotPositive | Numeric | {0} must be a positive number | 1301 |
IsNotNegative | Numeric | {0} must be a negative number | 1302 |
IsNotZero | Numeric | {0} must be zero | 1303 |
IsNotEven | Numeric | {0} must be even | 1304 |
IsNotOdd | Numeric | {0} must be odd | 1305 |
IsNotEqual | Numeric | {0} must be equals to {1} | 1306 |
IsNotInLast24Hours | TimeSpan | {0} must be in last 24 hours | 1401 |
IsNotInNext24Hours | TimeSpan | {0} must be in next 24 hours | 1402 |
IncorrectType* | Nullable types | {0} was expected. Got {1} instead. | --- |
* This message is not returned to Notification message stack. Instead it throws an exception, since it validates the type - which is developer responsability - and not its content.