gijew Posted July 31, 2006 Share Posted July 31, 2006 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! Link to comment https://forums.phpfreaks.com/topic/16148-regex-problem/ Share on other sites More sharing options...
effigy Posted August 1, 2006 Share Posted August 1, 2006 [code]<pre><?php $tests = array( 'FFFFFF', '#FFFFFF', '#ff', 'fff', 'asdkhyuy', '#artyui', '1234567', '', '000000' ); foreach ($tests as &$test) { $test = preg_match('/^[a-f\d]{6}$/i', $test) ? $test : 'xxx' ; } print_r($tests);?></pre>[/code] Link to comment https://forums.phpfreaks.com/topic/16148-regex-problem/#findComment-66837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.