Hello, I have the following case: ^[a-zA-Z0-9]+$ This work. Allows to enter only Latin characters. But when I insert a new line ( Enter ) in the textarea is obtained mistake. How to avoid this error when entering a new line with Enter? Thanks.
Can't you just include the newline character in your regex like below: ^[a-zA-Z0-9\n]+$ Code (markup):
If it's a textarea, you'd want FULL whitespace preservation, would you not? The above also strips SPACES -- if you want carriage returns, you probably want spaces too. ^[\w\s]+$ \s means all whitespace -- spaces, tabs and carriage return/linefeeds are matched. The \w is the same as a-zA-Z0-9 except it also includes underscore... which I usually would allow through as it's not usually a deal-breaker on anything. Basically the above is the same as: ^[a-zA-Z0-9_\r\n\t\v\f ]+$ Just a hell of a lot easier to say... though I'll often allow those other control characters through, then compress [\t\v\f]+ to a single space with a replace.
you need to use the modifier s to ignore new lines. you can find out more about the php modifiers here: http://php.net/manual/en/reference.pcre.pattern.modifiers.php