html - Angular ng-pattern: textarea format regex -
i want control form of user input in textarea on page. input has this:
that means 3 values in 1 row , semicolon between first , second , between second , third value.
by using regex validate it:
^((([^;]+);([^;]*);([^;]+))\n?)*$
it not work 100%, because validates input
value1;value2;value3 value1
as valid. problem new line , beginning of next value1. seems until first semicolon written after value1, value1 still appended end of value3 in previous line. how should change regex disable , mark every new incomplete line invalid?
i created js fiddle demonstrate: https://jsfiddle.net/tw2y5omc/3/
following regex:
^((?:[^;]+;){2}(?:[^;\n\r]+))$ # captures group # matches except semicolon, followed semicolon 2 times # afterwards except semicolon or newlines being bound end of string
if want allow empty values, use star instead:
^((?:[^;]*;){2}(?:[^;\n\r]*))$
demo on regex101.com
Comments
Post a Comment