View Single Post
  #11 (permalink)  
Old 10-07-09, 08:52 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by PopSmith View Post
I am thinking that my above use of preg_match would validate that the $c_fname variable, which is the sanitized output of the variable $first_name, contains only characters a-z in either upper or lower case as well as the period or underscore. The {1,15} would limit the preg_match to between 1 and 15 characters.
return preg_match("/^[a-zA-Z\._]{1,15}/")

I believe that's correct, although make sure you escape the period as shown above since it's a meta character. I'm not sure if you want the dollar-sign meta in there- it indicates matching at the end of the line (or before newline at the end) and I don't know if that's what you really want to do or not.

You might grab a copy of Regex Buddy and give it a try, I find it invaluable in creating and working out regex strings.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]

Last edited by End User; 10-07-09 at 08:54 AM.
The Following User Says Thank You to End User For This Useful Post:
PopSmith (10-07-09)