I need to validate my c# model class.
[Required(ErrorMessage = "Comma Separated String Required")]
[RegularExpression(@"", ErrorMessage = "Invalid Comma Separated String.")]
[RegularExpression(@"", ErrorMessage = "Duplicate Code.")]
public string CommaSeparatedString { get; set; }
I just tried the following regex, but it is not working for me.
((\s+)??(\d[a-z]|[a-z]\d|[a-z]),?)+?$
In my case, CommaSeparatedString
can be:
ASAEW1,ASAEW2,ASA,S4,ASAEW5,ASAEW6,ASAEW7 - Valid
ASAEW1,ASAEW2,ASA,S4,ASAEW5,ASAEW6,ASAEW7,ASAEW6 - Invalid - Duplicate ASAEW6
ASAEW1,ASAEW2,ASA,S4,ASAEW5,ASAEW6,ASAEW7, - Invalid - Comma at end
ASAEW1,ASAEW2,,ASA,S4,ASAEW5,ASAEW6,ASAEW7 - Invalid - No value between 2,3 comma
The above requirement should happen. Is there any possible way to check duplicates in comma-separated String? I need to show 'Duplicates code'
error message if CommaSeparatedString
consists of duplicates. How can I do this?