Page 1 of 1

a-Z0-9()[]^-_.

Posted: Sun Oct 04, 2009 11:55 am
by JKM
Could anyone please give me the regex 'code' for allowing only

Code: Select all

a-Z 0-9 - _ ( ) [ ] { } . ^

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
 
*/

Re: a-Z0-9()[]^-_.

Posted: Mon Oct 05, 2009 3:14 am
by freamer
Why not using something like? /^[a-z0-9()\[\]\^\-\_\.]+$/s

Read docs, the task you`re asking about is very easy.

Re: a-Z0-9()[]^-_.

Posted: Sat Oct 10, 2009 12:48 pm
by ridgerunner
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).