Allowing new line characters in javascript regex

假如想象 提交于 2019-12-24 10:55:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!