I would just like to know if there is a way in ASP.NET Core to allow users to enter the user name in a specific format, the format that I want is two letters then four numbers, or one letter then four numbers Ex."b4321" or "ba4321".
CodePudding user response:
You can add custom validation rules.
[RegularExpression(@"^[a-zA-Z]{2}[0-9]{4}$|^[a-zA-Z]{1}[0-9]{4}$"]
public string UserName { get; set; }
CodePudding user response:
If you have a class, you can maybe bind the property with "RegularExpressionAttribute". Here is a link of how to use it from the official microsoft docs: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.regularexpressionattribute?view=net-6.0