Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazorise Validation message based on response from API

$
0
0

I have a Blazor application which is using Blazorise. I have a password reset dialog which works great, however when sending the password to the server I do a check to verify the password has not been used before. When it has, I want to display a message under the text field. How do I do that with a Blazorise Validation and still maintain the original validation?

Dialog allowing user to reset password

<Fields><Field ColumnSize="ColumnSize.Is6"><FieldLabel RequiredIndicator>Password</FieldLabel><Validation Validator="@ValidatePassword"><TextEdit @bind-Text="@User.Password" Placeholder="Enter a Password" MaxLength="50" Role="TextRole.Password"><Feedback><ValidationError>Invalid password. Passwords must be between 8 and 30 characters long, one number, one lower and one upper case letter, and one special character.</ValidationError></Feedback></TextEdit></Validation></Field></Fields><Fields><Field ColumnSize="ColumnSize.Is6"><FieldLabel RequiredIndicator>Confirm Password</FieldLabel><Validation Validator="@ConfirmPassword"><TextEdit @bind-Text="@User.ConfirmPassword" Placeholder="Retype password" MaxLength="50" Role=" TextRole.Password"><Feedback><ValidationError>Password does not match!</ValidationError></Feedback></TextEdit></Validation></Field></Fields>

@code {const string passwordPattern = @"^(?=.[a-z])(?=.[A-Z])(?=.\d)(?=.[^\da-zA-Z]).{8,30}$";

    void ValidatePassword(ValidatorEventArgs e)    {        bool isMatch = Regex.IsMatch(Convert.ToString(e.Value), passwordPattern);        e.Status = isMatch ? ValidationStatus.Success : ValidationStatus.Error;    }    void ConfirmPassword(ValidatorEventArgs e)    {        var confirmPassword = Convert.ToString(e.Value);        bool isMatch = Regex.IsMatch(confirmPassword, passwordPattern);        if (!isMatch)        {            e.Status = ValidationStatus.Error;            e.ErrorText = "Invalid password. Passwords must be between 8 and 30 characters long, one number, one lower and one upper case letter, and one special character.";        }        else if (confirmPassword != User.Password)        {            e.Status = ValidationStatus.Error;        }        else        {            e.Status = ValidationStatus.Success;        }    }

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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