I have a specific validation scenario that I am trying to solve using regexp pattern in JavaScript. I am struggling to write a suitable regular expression.
The rule is that validation must fail if a comma appears anywhere within a multiline piece of text that is enterred by the user into a text area, but only if it appears BEFORE a pipe character on the same line. It is assumed that every line will contain a pipe character somewhere (this is enforced elsewhere).
Examples below should clarify the requirement:
Example 1 - PASS: No commas
one|One
two|Two
three|Three
Example 2 - PASS: Comma appears, but after pipe character and so is ok
one|One
two|Tw,o
three|Three
Example 3 - FAIL: Comma appears before pipe character
o,ne|One
two|Two
three|Three
Example 4 - FAIL: Comma appears before pipe character
one|One
two,|Two
three|Three
The closest attempt I have got so far is:
/^[^,]+$/g
However, this doesn't take into account that a comma after the pipe character is permitted.