Hi, im trying to use radzens validator to validate a radzen grids fields.
I've got a field with UK phone numbers inside it and was wondering how to validate users input if they put for example letters inside? I want to accept numbers only and a length of 11 digits only.
Hi Korchev,
Are there any existing validators which can check if user input is unique? for example if user tries to enter email address which already exist in the radzen grid table, it will show up an error message which says email is not unique or something like this?
Thank you
is this possible to do by creating a custom validator? if so, could you point me in the right direction for resources on how to create the custom validator please? thanks
Check the implementations that I linked above. You can create a custom validator and set all existing emails as a property and then check against if that property contains the component value. Something like:
namespace MyApp
{
public class UniqueEmailValidator : Radzen.Blazor.ValidatorBase
{
[Parameter]
public override string Text { get; set; } = "Email exists";
protected override bool Validate(IRadzenFormComponent component)
{
var email = component.GetValue();
return email != null && Emails != null && !Emails.Contains(email.ToString());
}
[Parameter]
public IEnumerable<string> Emails { get; set; }
}
}
hi korchev! I have successfully implemented this and it is working great however, I have 1 issue, when I edit the data and hit save changes, it says the number already exist, how can I overcome this issue?