Smart Detection
Automatically detect and validate input types using Validixty's intelligent detection system.
What is Smart Detection?
Smart Detection in Validixty uses pattern recognition and machine learning techniques to automatically identify the type of input data and apply the appropriate validation rules. This eliminates the need to manually specify validation types for unknown or mixed data sources.
Why Use Smart Detection?
- Automatic Recognition: No need to specify data types manually
- Flexible Input: Handles mixed or unknown data formats
- Confidence Scoring: Provides validation confidence levels
- Adaptive Learning: Improves accuracy over time
Before Using Validixty
Without smart detection, you might need complex type detection logic:
public ValidationResult DetectAndValidate(string input)
{
// Manual type detection
if (IsEmail(input))
{
return ValidateEmail(input);
}
else if (IsPhoneNumber(input))
{
return ValidatePhone(input);
}
else if (IsCreditCard(input))
{
return ValidateCreditCard(input);
}
else if (IsIBAN(input))
{
return ValidateIBAN(input);
}
else if (IsURL(input))
{
return ValidateURL(input);
}
else
{
return new ValidationResult(false, "Unknown input type");
}
}
private bool IsEmail(string input)
{
return Regex.IsMatch(input, "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$");
}
private bool IsPhoneNumber(string input)
{
return Regex.IsMatch(input, "^[\\+]?[1-9][\\d]{0,15}$");
}
private bool IsCreditCard(string input)
{
return Regex.IsMatch(input, "^\\d{13,19}$");
}
// ... more detection methods
After Using Validixty
With Validixty's Smart Detection, validation becomes automatic:
using Validixty.Core;
var smartValidator = new SmartValidator();
var result = smartValidator.Validate("+201234567890");
// result.FieldName will be "PhoneNumber"
// result.IsValid will be true
// result.Confidence will be 0.95 (95% confidence)
How It Saves Time
- Eliminates manual detection: No need to write type detection logic
- Reduces complexity: Single API call for any input type
- Improves accuracy: Advanced pattern recognition
- Future-proof: Automatically handles new data types
Usage Examples
Basic Smart Validation
var smartValidator = new SmartValidator();
// Phone number detection
var phoneResult = smartValidator.Validate("+201234567890");
Console.WriteLine($"Type: {phoneResult.FieldName}, Valid: {phoneResult.IsValid}");
// Email detection
var emailResult = smartValidator.Validate("user@domain.com");
Console.WriteLine($"Type: {emailResult.FieldName}, Valid: {emailResult.IsValid}");
// Credit card detection
var cardResult = smartValidator.Validate("4111111111111111");
Console.WriteLine($"Type: {cardResult.FieldName}, Valid: {cardResult.IsValid}");
Confidence-Based Validation
var result = smartValidator.Validate("some_input");
if (result.Confidence > 0.8) // High confidence
{
if (result.IsValid)
{
Console.WriteLine($"Validated {result.FieldName} with high confidence");
}
}
else if (result.Confidence > 0.5) // Medium confidence
{
Console.WriteLine($"Detected {result.FieldName} with medium confidence");
}
else
{
Console.WriteLine("Input type unclear, manual validation needed");
}
Batch Smart Validation
var inputs = new[]
{
"+201234567890",
"user@domain.com",
"4111111111111111",
"GB29 NWBK 6016 1331 9268 19",
"unknown_input"
};
foreach (var input in inputs)
{
var result = smartValidator.Validate(input);
Console.WriteLine($"{input} -> {result.FieldName} (Confidence: {result.Confidence:P1})");
}
Custom Smart Validation Rules
// Register custom patterns for smart detection
smartValidator.RegisterPattern("CustomID", "^CUST\\d{6}$");
smartValidator.RegisterPattern("OrderNumber", "^ORD-\\d{4}-\\d{4}$");
// Now it can detect these custom types
var customResult = smartValidator.Validate("CUST123456");
Console.WriteLine($"Detected: {customResult.FieldName}"); // "CustomID"
Integration with Fluent API
// Use smart detection within fluent validation
var complexResult = Validation.For("Smart Form")
.Check(x => smartValidator.Validate(x.Email).IsValid, "Invalid email")
.Check(x => smartValidator.Validate(x.Phone).FieldName == "PhoneNumber", "Invalid phone")
.Check(x => smartValidator.Validate(x.PaymentInfo).FieldName == "CreditCard", "Invalid payment")
.Validate();