[英]Allow returnline in textarea with regular expression
I would like to allow returnlines in a Form textarea . 我想在Form 文本区域中允许使用换行符 。 I haven't found the way to add this possibility to my regular expression .
我还没有找到将这种可能性添加到正则表达式中的方法 。 Will the return line be stored in the database?
返回行将存储在数据库中吗?
Here is the HTML form: 这是HTML表单:
<form method="post" action="#">
<textarea name="description" spellcheck="true" maxlength="500"></textarea>
</form>
And the PHP code with the regular expression to regulate the textarea
input ( true = match the regex = store to database): 以及带有正则表达式的PHP代码来调节
textarea
输入( true =匹配regex =存储到数据库):
if (!preg_match("/^[a-zàâäèéêëîïôœùûüÿç0-9 !?’',.-]+$/i", $POST['description'] )) {
return false;
}
return true;
}
You could match new lines (and carriage returns) by adding \\n
and \\r
: 您可以通过添加
\\n
和\\r
来匹配新行(和回车符):
/^[a-zàâäèéêëîïôœùûüÿç0-9 \n\r!?’',.-]+$/i
But maybe you want to allow all types of white space (like tabs, non-breaking space, ...). 但是也许您想允许所有类型的空格(例如制表符,不间断空格等)。 Then you can better use
\\s
: 然后,您可以更好地使用
\\s
:
/^[a-zàâäèéêëîïôœùûüÿç0-9\s!?’',.-]+$/i
Listing all allowable letters might be difficult. 列出所有允许的字母可能很困难。 There will always be that one other character... like
ò
. 总是会有另一个字符……像
ò
。 If you are willing to allow anything that could be called a letter in some language or alphabet (even Greek, Cyrillic), then use the \\pL
escape in combination with the unicode modifier u
at the end. 如果您愿意使用某种可以用某种语言或字母(甚至是希腊语,西里尔字母)组成的字母,则可以使用
\\pL
转义\\pL
与unicode修饰符u
结合使用。
Note you can also use \\d
for matching digits: 请注意,您也可以使用
\\d
来匹配数字:
/^[\pL\d\s!?’',.-]+$/iu
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.