Regex username for codeigniter route
-
26-04-2021 - |
Question
I am trying to get my regex to not allow the following words:
- create
- Forum
I also would like to allow only 1 underscore..
Here is what I have so far:
$route['(^[A-Za-z][A-Za-z0-9]{3,20}+$)'] = "users/index";
Solution
Put the routes you don't want to match before that one (it will stop at the first matched route):
$route['create(/.*)?'] = "create$1";
$route['forum(/.*)?'] = "forum$1";
$route['(^[A-Za-z][A-Za-z0-9]{3,20}+$)'] = "users/index";
OTHER TIPS
Hmm, this is the closest I can get:
^((?:(?!create|Forum)[A-Za-z0-9]){3,20})$
Gotta leave now. Good luck with this!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow