I used the following regular expression:
[RegularExpression(@"^(Mr. .*|MR. .*|MRS. .*|Mrs. .*|MS. .*|Ms. .*|DR. .*|Dr. .*)", ErrorMessage = "Greeting must begin with Mr., Mrs., Ms., or Dr. and be followed by a name.")]
public string? Greeting { get; set; }
How can I force user to enter space after Mr.
, MR.
, MRs.
, Mrs.
, then at least one character after the space.
For example: if they enter Mr. Joe Doe
or Mr. Joe
is valid but they enter Mr.
with space only or Mr.
without space is invalid.