Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: validate value type short

$
0
0
Not exactly sure if this is what you're looking for, but hopefully it will help:
public class MyClass
{
    public string NumberInput { get; set; }
}

public class MyClassValidator : AbstractValidator<MyClass>
{
    public MyClassValidator()
    {
        RuleFor(x => x.NumberInput)
            .Must(BeNumeric)
            .WithMessage(">> Put your message here to let the user know that their input is not a valid number <<");
    }

    private bool BeNumeric(string input)
    {
        int result;
        return int.TryParse(input, out result);
    }
}

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>