Forum Moderators: coopster
Well, I've spent many many hours on this and i'm finally getting it to work. Now i'm fixing up the little stuff and adding/ removing some features.I am setting up custom titles and i'd like people to be use basic characters such as exclamation marks, periods, and possible dashes.
This is the line that controls validation:
elseif ((!preg_match("/^[.!a-zA-Z0-9]*$/", $newtitle)) ¦¦ (strlen($newtitle) < 2)) { message_die(GENERAL_MESSAGE, 'That Rank is Invalid, it must only contain characters A-Z, a-z and 0-9. For more specific titles talk to an admin.'); } I tried googling this but all the examples I found were mainly just for email addresses and showed you how to use the code, not write it. :evil:
How would I have to modify this code to get more characters?
thx
[edited by: coopster at 11:27 am (utc) on Feb. 23, 2005]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]
elseif ((!preg_match("/^[a-zA-Z0-9]*$/", $newtitle)) ¦¦ (strlen($newtitle) < 2)) { message_die(GENERAL_MESSAGE, 'That Rank is Invalid, it must only contain characters A-Z, a-z and 0-9. For more specific titles talk to an admin.'); }
That regex will allow users to post data that are words (alpha numerics) and non-words (!*&%#@-_ and so on). It also requires that there be at least 1 character in the match. If you need to further restrict it, say allow words, but only the period and question mark characters then:
/^[\w\.\?]+?$/
(I've escaped the . and? characters with a backslash as they have a special meaning in regular expressions)
I'm not 100% sure about permitting a! character as it is used in regex's, but only in combination (What I mean to say is that you can use it, but I don't know if it has to be escaped with a backslash).