Phill Sparks wrote: > > > On Tue, Mar 11, 2008 at 11:23 AM, William Piper <[EMAIL PROTECTED] > <mailto:billy%40kersting.com>> wrote: > > > > Leelakh Ran wrote" "On 3/11/2008 2:25 AM":" > > > > > I need to restrict my feed data as below. > > > 1.) First character should be from a-zA-Z0-9 > > > 2.) Then after it can be a-zA-Z0-9,space_.@,- > > > > > > Please help. How can write it on code? > > > > Try this: > > if(preg_match("[EMAIL PROTECTED]",$source)){ > > //looks good > > } > > else{ > > //other character found > > } > > > > A few notes about regex, you do not need to use {1} since a [] match > is a single character already. If you want to match a '-' then use > that as the last character in the [], this way it is not part of a > range. '.' does not need to be escaped in []. \d (digits), \w (word > characters) and \s can all be used in []. Not sure why the '*' crept > in? And lastly, you're missing the comma :-p > > You can change the * here to decide how many of the last [] are > matched. * is zero or more, + is one or more, ? is zero or one, or > you can use {n} or {x,y} (n is exactly how many, x, y is no less than > x and no more than y). > > /^[\w\d][\w\d\s,[EMAIL PROTECTED]/ > > Looks good though :-)
My bad Phil, I wrote it off the top of my head without testing it around 0800 this morning (and without coffee :-) FYI, to my understanding the "-" is fine as long as you escape it, hence the "\-". The period doesn't hurt to be escaped, agreed though it didn't need to be, it's just a habit of mine. Thanks for the input, William Piper