CodeIgniter Forums
Solved: symbol validation check question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Solved: symbol validation check question (/showthread.php?tid=70402)



Solved: symbol validation check question - wolfgang1983 - 04-05-2018

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


RE: symbol validation check question - wolfgang1983 - 04-05-2018

Found solution did like

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



RE: Solved: symbol validation check question - jreklund - 04-05-2018

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
_


RE: Solved: symbol validation check question - wolfgang1983 - 04-05-2018

(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?


RE: Solved: symbol validation check question - jreklund - 04-05-2018

It won't allow space.