April 17, 200818 yr hey i'm trying to work out how to limit the characters that can be accepted in a form but all i can find is how to check if a character exists in a string and i dont really want to make a list of every posible character to check against. is there some way so that if doesn't only contain the acceptable characters it will return false? e.g one of the fields is for color , i want it to check that all the characters are legal hex color code characters (a-f, 0-9) and return false if there is a character not in that range thanks
April 17, 200818 yr you are talking about regular expressions even if you don't know it A regular expression (checked with ereg() or preg_match()) looks something like this: /^([A-Za-z ]*)/ That means any character in: - A to Z - a to z - [space] repeated any number of times (* means 0 to infinity) Regex's are a bitch to learn, but are very useful. Do a google, and prepare for your brain to melt An example for a hex code is: /^([#]{0,1})([0-9A-Fa-f]{6}|[0-9][A-Fa-f]{3})/ The caret (^) means "from the beginning), so breaking the actual regex down, ([#]{0,1}) = a hash, either not there or only 1 of [0-9][A-Fa-f] = any of 0123456789AaBbCcDdEeFf {6} = exactly 6 of the characters within the preceding range | = or so "from the beginning, a hash (or no hash) followed by either 3 or 6 of any of the following 0123456789AaBbCcDdEeFf"
April 17, 200818 yr Author thank you , thats exactly what i was looking for ^^ i knew there had to be a function somewhere for it but i just couldn't find it >< /me prepares to melt what little is left of her brain
Create an account or sign in to comment