i need to validate a text box for this format of data input –
“TeSt12-12TeSt,12Test-Ab12,….”
which basically is a series of key-value (key hyphen value) split using a comma (,)
Readlike
anyAlphaNumeric followed by hyphen anyAlphaNumeric then “optional from here” comma and anyAlphaNumeric followed by hyphen anyAlphaNumeric then comma and anyAlphaNumeric followed by hyphen anyAlphaNumeric…
Here 1s can be A-Z, a-z, 0-9
Examples –
11-11 is valid
111-111, is invalid (comma should be followed by another key-value set)
1-1,1-1 is valid
1- is invalid (value is missing after hyphen)
1-1,111-111,11-11111,111-111111 is valid
All right:
or (as a non-verbose regex):
Be aware that
\wwill also match the underscore (and, in a .NET environment, may also match Unicode letters and digits. If you don’t want that, use[A-Za-z0-9]instead of\w.