Change the Color of the Text Based on its Value in Blazor TextBox
7 Oct 20211 minute to read
The color of the TextBox can be changed by validating its value using regular expression in the Input
event for predicting the numeric values as demonstrated in the following code sample.
@using Syncfusion.Blazor.Inputs
<SfTextBox Placeholder="Enter a Numeric Values" FloatLabelType="@FloatLabelType.Auto" Input="OnInput" CssClass="@CssClass"></SfTextBox>
@code {
public string CssClass { get; set; }
public void OnInput(InputEventArgs args)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(args.Value, "^[0-9]*$")){
CssClass = "e-error";
}
else {
CssClass = "e-success";
}
this.StateHasChanged();
}
}