48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using Enciphered.Blazor.UIComponents.Validation;
|
|
|
|
namespace Enciphered.Blazor.UIComponents.Demo;
|
|
|
|
public class ContactFormValidator : FormValidator
|
|
{
|
|
public ContactFormValidator()
|
|
{
|
|
RuleFor("name",
|
|
displayName: "Name",
|
|
required: true,
|
|
minLength: 2);
|
|
|
|
RuleFor("email",
|
|
displayName: "Email",
|
|
required: true,
|
|
pattern: @".+@.+\..+",
|
|
message: "Please enter a valid email address.");
|
|
|
|
RuleFor("password",
|
|
displayName: "Password",
|
|
required: true,
|
|
minLength: 6);
|
|
|
|
RuleFor("age",
|
|
displayName: "Age",
|
|
min: 0,
|
|
max: 150);
|
|
|
|
RuleFor("birthdate",
|
|
displayName: "Birth Date",
|
|
custom: value => !DateOnly.TryParse(value, out _) ? "Please enter a valid date." : null);
|
|
|
|
RuleFor("preferredtime",
|
|
displayName: "Preferred Time",
|
|
custom: value => !TimeOnly.TryParse(value, out _) ? "Please enter a valid time." : null);
|
|
|
|
RuleFor("appointment",
|
|
displayName: "Appointment",
|
|
custom: value => !DateTime.TryParse(value, out _) ? "Please enter a valid date and time." : null);
|
|
|
|
RuleFor("confirmation",
|
|
displayName: "Confirmation",
|
|
required: true,
|
|
custom: value => value != "CONFIRM" ? "You must type CONFIRM to proceed." : null);
|
|
}
|
|
}
|