How can I al开发者_JS百科low only letters and special characters with a regular expression?
I suggest you use GSkinner's REGEX builder and experiment with a lot of the examples on the right hand side. There are are many variations to get this job done. If you want to be explicit you can use:
/[a-zA-Z!@#$%¨&*()-=+/*.{}]/
Tony's answer will also work, but includes more extra characters than the ones you've defined in your comment.
This
$str = $_REQUEST["htmlstringinput"];
preg_match("([\w\-]+[@#%.])", $str);
for letters, numbers and special characters in this special character range [@#%.]
are allowed
and this
$str = $_REQUEST["htmlstringinput"];
preg_match("([-a-zA-Z]+[@#%.])", $str);
for only letters and special characters in the same special character range as above Worked for me. For further reading and research you can go to : http://gskinner.com/RegExr/
/[\p{L}\p{P}]+/u
matches letters and punctuation characters. Or what did you mean by "special characters"?
all characters not a number? how bout this:
/[^\d]*/
Use following code in .htaccess to block all URLs with number (as per OP's comments)
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} ![0-9]
RewriteRule ^user/ /index.php?goto=missed [NC,L]
精彩评论