I am using this regex: preg_match('~[^A-Za-z0-9\+\-"]~', $incoming);
How can I add empty spaces here?
An example:
word1 word2
I mean the space between word1 and word2. I want to allow only one space. Not like word1 word2 (there are two spaces between these words).
But word1 word2 word3 shall be allowed.
Is that possible?
This is my current function:
$incoming = '"test test test"';
$forbidden_chars = preg_match('~[^A-Za-z0-9\+\-"\s]~', $incoming);
if( /*$string_length < 150 &&*/ !$forbidden_chars){
$valid_query = TRUE;
}
else{
$valid_query = FALSE;
}
$valid_query should be true, but it is still false.
Why?
All examples:
"test" test +test -test test test "test test" shall be allowed, this shall also be possible test test test this not: test test (2 Spaces between the words)
If you are trying to match the following:
Try this:
EDIT 1:
Based on what I could figure out from your examples, here’s what you need:
This will match 1 or more “words” that are single space separated. This allows optional leading and trailing single space.