I would like to allow returnlines in a Form textarea . 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:
<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):
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
:
/^[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
:
/^[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.
Note you can also use \\d
for matching digits:
/^[\pL\d\s!?’',.-]+$/iu
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.