I have validation logic at my model level service level and UI level.
Example:
public int Id { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
[Required]
[RegularExpression(RegularExpressions.UK_PHONE_REGEX)]
public string PhoneNumber { get; set; }
public string Notes { get; set; }
I'm encountering an issue where I'm able to manually input data into my database using SSMS, even if it doesn't pass the validation rules I've set in my code.
For example, I can enter a phone number like '8' or '10000', which should not be allowed according to the regex pattern I'm using.
However, when I tested the regex on an external site like https://regex101.com/, it correctly did not accept those values. Is there a way to enforce the validation rules in the database itself to prevent this issue?
I also used Entity Framework Core for the database connections, so Add-Migration
and Update-Database
was done.