soadlink Posted January 3, 2007 Share Posted January 3, 2007 This is probably very easy, I just cant think of a SIMPLE way to do it:I'm looking for a php function that will search a string and output whether or not the string contains all hexadecimal characters or not. So here is a sample:[code=php:0]$string = 'abcdef1234567890z';// function to check itecho 'Your string does NOT contain only hexadecimal characters';[/code]or if the string was 'abcdef1234567890',[code=php:0]echo 'Your string contains all hexadecimal characters.';[/code]Also on a side note, I need a simple way (javascript code maybe) to disable a "Submit" button in an html form until a certain number of characters have been entered into a text box that is located in that same form. Any help there would be good too (will most like need some javascript).Thanks 8) Quote Link to comment Share on other sites More sharing options...
MCP Posted January 3, 2007 Share Posted January 3, 2007 See [url=http://www.php.net/manual/en/function.preg-match.php]preg_match[/url]Something along the lines of:[code]if (preg_match("/^[0-9a-fA-F]$/",$string)){ //it matches only hexadecimal} else { //it doesn't}[/code](untested) Quote Link to comment Share on other sites More sharing options...
soadlink Posted January 3, 2007 Author Share Posted January 3, 2007 I tried your code but it didn't work. I used a few different test strings such as: abc123, abc, 123... all turn out to say it doesn't contain only hex, when it does.But I did try just a single "1" and it said it was all hex, which is true. ??? Quote Link to comment Share on other sites More sharing options...
MCP Posted January 3, 2007 Share Posted January 3, 2007 I did say it was untested! Sorry about that, try:[code]if (preg_match("/^[0-9a-fA-F]+$/",$string)){ //it matches only hexadecimal} else { //it doesn't}[/code]You can change the "+" to a "*" to allow empty strings Quote Link to comment Share on other sites More sharing options...
soadlink Posted January 3, 2007 Author Share Posted January 3, 2007 Wahoo! That works great 8) Thank you very much! ;D :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.