It would probably be \n what you want, so:
preg_match('#^[a-z0-9\-+, .\#*()\\/\n]+$#i', $ads_description)
Of course you can use the \s which will amount to \n, to space and tab (\t), so summarize the regular expression for:
preg_match('#^[a-z0-9\-+,.\#*()\\/\s]+$#i', $ads_description)
Example in IDEONE: https://ideone.com/wMIwLL
Just for the record, a-z does not accept accents, only accepts a,e,i,o,u,b,c,d..., letters like ã, õ, etc need to be specified, so it should look like this (to accept the letter a with accents, a short example just to understand):
preg_match('#^[a-z0-9ãáà\-+,.\#*()\\/\s]+$#i', $ads_description)
But it is possible to simplify using \p{L} (probably the data is in utf-8 so use the modifier u), thus:
<?php
$ads_description = '250.000km, Revisão feita.
Inspeccionado ate Julho 2018.
Novo kit embreagem, travoes, cardans. Encontra-se em muito bom estado.';
if (!preg_match('#^[\p{L}0-9\-+,.\#*()\\/\s]+$#iu', $ads_description)) {
echo 'Erro';
} else {
echo 'Certo';
}
Se underline/underscore _ can also be accepted, so you could summarize a-Z0-9 and _ with metacharacter \w (a-z is case insensitive, which would dispense with the modifier i after the #), so this:
preg_match('#^[\w\-+,.\#*()\\/\s]+$#', $ads_description)
It would be the same as:
preg_match('#^[a-z0-9\-+,.\#*()\\/\s]+$#i', $ads_description)
I entered exactly the one that sent me, but it gives me an error when I insert this message "250.000km, Revision made. Inspected until July 2018. New kit clutch, brakes, cardans. It is in very good condition." will have introduced some character invalid?
– Rufus1090
whereas I am using if(! preg_match......)
– Rufus1090
@Rufus1090 the
!makes the denial, your intention is what? That "enter" the IF when you have right? Then you have to take the!, now if the intention is not to enter the IF then this right, please create an example in https://ideone.com work and sends me to see why you don’t join IF.– Guilherme Nascimento
the intention is that only accept these characters. Hence the use of !
– Rufus1090
for example, if you don’t have these characters, it shows message.
– Rufus1090
example: if(!preg_match('# [ w-+,.#*() / s]+$#', $ads_description)) { $errors[] = "
– Rufus1090
@Rufus1090 puts an example in IDEONE. Here it seems this normal.
– Guilherme Nascimento
Yes the intention is the same, "IF THE TEXTAR FIELD CONTAINS OTHER CHARACTERS THAN THESE, IT OF THE ERROR"
– Rufus1090
I introduced this sentence and it accuses of error. "250.000km, Revision made. Inspected until July 2018. New clutch kit, brakes, cardans. It is in very good condition."
– Rufus1090
@Rufus1090 no use UPPERCASE EVERYTHING, the problem is that you haven’t posted the full code and I can’t read minds, let’s get down to business, here it works https://ideone.com/DKsj92 ---- If this does not work is due to another character that has nothing to do with line breaks, I have already spoken creates an example of the error in IDEONE and sends me: https://ideone.com if it will not be impossible to help you
– Guilherme Nascimento
this is https://ideone.com/7p2YZv
– Rufus1090
@Rufus1090 this is not a functional example of the problem, it’s just a piece of code pasted that does not run, I asked to create an example works of the problem, that is a summary example with the part that matters and that really works. All right forget it, I think I’ve already found the problem anyway and I’m editing the answer. Wait a few minutes
– Guilherme Nascimento
@Rufus1090 ready, I edited the answer.
– Guilherme Nascimento
K.. I understand the error, when I Preciono ENTER(line below), it simply activates the error.. That’s why it doesn’t let go.. s does not result at all... nor the
– Rufus1090
OK, is there any way to accept all characters of the type ()-*$%--- ?
– Rufus1090
@Rufus1090 put your script all for me to test please, send the http://pastebin.com and send me the link here
– Guilherme Nascimento
A question, what if I just wanted the user not to be able to put "<>, «», #, |, how would I do it? ?
– Rufus1090
@Rufus1090 like this:
if (preg_match('#[<>«»|?]#', $ads_description)) { echo 'Não pode "<>, «», #, |, ?"'; } else { echo 'Funcionou'; }– Guilherme Nascimento