Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
JKM
Forum Contributor
Posts: 221 Joined: Tue Jun 17, 2008 8:12 pm
Post
by JKM » Sun Oct 04, 2009 11:55 am
Could anyone please give me the regex 'code' for allowing only
Code: Select all
if(!preg_match("A-Za-z0-9_^(){}[]-|~.", $_GET['bn'])) {
//error
}
/* index.php?bn=Hey returns:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash
*/
freamer
Forum Newbie
Posts: 5 Joined: Mon Oct 05, 2009 3:08 am
Post
by freamer » Mon Oct 05, 2009 3:14 am
Why not using something like? /^[a-z0-9()\[\]\^\-\_\.]+$/s
Read docs, the task you`re asking about is very easy.
ridgerunner
Forum Contributor
Posts: 214 Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT
Post
by ridgerunner » Sat Oct 10, 2009 12:48 pm
This one should do the trick...
Code: Select all
if (!preg_match('/^[A-Za-z0-9\-_()[\]{}.^]+$/', $_GET['bn'])) {
//error
}
freamer's code ('/^[a-z0-9()\[\]\^\-\_\.]+$/s') almost works (but fails to match uppercase letters or the curly braces).