Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression issue with Fluent validation

Probably very silly issue but looking for help on this .

I am adding MVC Fluent validation rules to model property but for some reason one of the validation rule is failing. Added a regular expression to allow english and spanish characters and no numeric or special characters allowed except - and '. For some reason when user enters more than one valid character as input the error is still displayed.

Error is still displayed when User Input is aA

I am using this RegE @"^[a-zA-Z-']$") to allow users to english and spanish characters and no numeric or special characters allowed except - and '.

Any help is appreciated.

  RuleFor(x => x.FirstName)              
 .NotEmpty().WithLocalizedMessage(ResourceAreas.Messages.Message_PersonalDetails_1001_firstname)
 .Length(1, 
     20).WithLocalizedMessage(ResourceAreas.Messages.Message_Onboarding_100006_maxlength) 
 .Matches(@"^[a-zA-Z-']$").WithLocalizedMessage(ResourceAreas.Messages.Message_Onboarding_PersonalDetails_100007_validname);
like image 221
user845405 Avatar asked Feb 12 '23 08:02

user845405


1 Answers

Updating the RegE worked - Thankyou all

@"^[a-zA-Z-']*$";
like image 130
user845405 Avatar answered Feb 13 '23 22:02

user845405