I have a string that should be valid only if it has 2 characters and it is delimited by commas.
AD,AC,AN,JP (valid)
AD (valid) if user enter only one it must be validate
Must return invalid if it’s a number or any other character besides comma or its length is greater than 2.
AD,12,AN,JP (invalid)
AAD,12,AN,JP (invalid)
AA,CC,ANA,JP (invalid)
AA,#C,AA,JP (invalid)
This assumes that the input is always uppercase:
If, on top of validating the input, you want to extract the data, you can then perform a simple split on the comma (regex split is not necessary):