Jump to content


Regex problem

  • Please log in to reply
1 reply to this topic

#1 gijew

  • Members
  • PipPipPip
  • Advanced Member
  • 240 posts
  • LocationCalifornia

Posted 31 July 2006 - 10:11 PM

I'm trying to validate as much as I can html color codes that come through. 

What I'm trying to achieve is...
1.  Validate if 6 alpha numeric characters are being sent without the # sign.
2.  If more or less than 6 alpha numeric characters are being sent, default to xxx.
3.  If any other character is being sent other than 6 alpha numeric characters, default to xxx.

End result, no error messages, just defaults unless a valid 6 character alpha numeric string is found.

I know that I'm going about this wrong so I started using some regex again which I suck at.  If you require, I can show what I have.  It's not right, it's not good and it's not clean but it's what I know. 

Can someone help me out with a good search and replace regex here?  Thanks!
I'm considered good looking in some countries

#2 effigy

  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 01 August 2006 - 04:37 AM


	$tests = array(

	foreach ($tests as &$test) {
		$test =
			preg_match('/^[a-f\d]{6}$/i', $test) ?
			$test :
			'xxx' ;



Regexp | Unicode Article | Letter Database

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users