问题
I am using live validation on my site (from livevalidation.com), I have a text area where I need to allow new line / line feed / return characters, but despite my best efforts I am failing miserably. I have tried \n \r \v \s\S each with \ escape and without.
This is my code without the use of the above chars:
my_notes.add( Validate.Format, { pattern: /^[a-zA-Z0-9ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïñòóôõöøùúûüýÿ\.\,\-\/\']+[a-zA-Z0-9ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïñòóôõöøùúûüýÿ\.\,\-\/\' ]+$/i } );
Any suggestions would be greatly appreciated.
回答1:
The /m modifier allows the pattern to match across multiple lines, where you have /i at the end of your pattern try /mi instead
来源:https://stackoverflow.com/questions/10335550/allowing-new-line-characters-in-javascript-regex