Brandon_R Posted July 31, 2009 Share Posted July 31, 2009 Hello, i need a regular expression to validate that an entered string only contains hex values. preg_match Thank you Brandon_R Link to comment https://forums.phpfreaks.com/topic/168251-preg_match-expression-for-hex-value/ Share on other sites More sharing options...
Adam Posted July 31, 2009 Share Posted July 31, 2009 /^0x[0-9A-F]{1,4}$/i Source: http://www.perlmonks.org/?node_id=629540 Link to comment https://forums.phpfreaks.com/topic/168251-preg_match-expression-for-hex-value/#findComment-887545 Share on other sites More sharing options...
.josh Posted July 31, 2009 Share Posted July 31, 2009 that will only match if there is one hex value, though. You said values so you will have to provide an example of how they are delimited. space? comma? etc...(show an actual example of content) Link to comment https://forums.phpfreaks.com/topic/168251-preg_match-expression-for-hex-value/#findComment-887616 Share on other sites More sharing options...
Brandon_R Posted July 31, 2009 Author Share Posted July 31, 2009 Just an 7 or 8 value long hex string such as 123ADF22 The input field is <input type="text" name="hex" value="" maxlength="8" /> Brandon+R Link to comment https://forums.phpfreaks.com/topic/168251-preg_match-expression-for-hex-value/#findComment-887920 Share on other sites More sharing options...
roopurt18 Posted July 31, 2009 Share Posted July 31, 2009 Well hex values typically start with 0x. What you've provided is just a series of hex digits. So based on your latest post: preg_match( '/[a-fA-F0-9]{1,8}/', $value ) Link to comment https://forums.phpfreaks.com/topic/168251-preg_match-expression-for-hex-value/#findComment-887923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.