Welcome Guest, Not a member yet? Register   Sign In
Solved: symbol validation check question
#1

(This post was last modified: 04-05-2018, 02:00 AM by wolfgang1983.)

Hi,

I have this code below which lets me validate folder names.

PHP Code:
$is_correct_foldername strpbrk($this->input->post('folder'), "\\/?%*:@#${}|\"<>"); 

How can I make sure folder name contains no spaces. As you can see in my strpbrk I have symbols that are not allow.

Thanks
Reply
#2

Found solution did like

PHP Code:
$is_correct_foldername strpbrk($this->input->post('folder'), "\\/?%*:@#$|\"<>" "{}" " "); 
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#3

(This post was last modified: 04-05-2018, 11:18 AM by jreklund.)

Personally I would match characters I want instead of those I don't want. Right now you can use chines letters in your folder name, are you allowed to do so?

PHP Code:
$re '/\W/'// \W matches any non-word character (equal to [^a-zA-Z0-9_])

$str $this->input->post('folder');

$is_correct_foldername = !preg_match($re$str) ? true false

This will give you false on every character except:
a-z
A-Z
0-9
_
Reply
#4

(04-05-2018, 11:17 AM)jreklund Wrote: Personally I would match characters I want instead of those I don't want. Right now you can use chines letters in your folder name, are you allowed to do so?

PHP Code:
$re '/\W/'// \W matches any non-word character (equal to [^a-zA-Z0-9_])

$str $this->input->post('folder');

$is_correct_foldername = !preg_match($re$str) ? true false

This will give you false on every character except:
a-z
A-Z
0-9
_

And spaces?
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#5

It won't allow space.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB