Hello, I'm looking for a conditional statement that checks a field entry for the presence of any digit (0 - 9). Along the lines of: if ($variable {[I]where I'm lost[/I]}) Code (markup): I appreciate any help in this matter...
You could of read a doc. You could of used google. There's so many things you could of done BEFORE asking for help. If you're looking to verify if a value is in numeric form use is_numeric() like so: $blah = 25; if (is_numeric($blah)) { print "Yep..it's a number\n"; } else { print "Not a number!\n"; } PHP: If you just want to see if a number exists IN a string you could use a simple regex: preg_match("/[0-9]/", $blah)
Don't presume to know what I did before I started the topic. Yes, I could "of" done those things. I did those things, but I didn't find what I was looking for. If I didn't do my research before starting a topic, as far as coding was concerned, I'd be posting here more often...
I didn't "presume". I actually knew you didn't bother to try to find the answer your on own. A simple Google search for "PHP Numbers Only" or "PHP Numeric Values" or "PHP is_numeric()" would of returned your answer. A simple trip to PHP.net and a 10 second glance under numeric functions would of also returned your answer. You didn't check. But regardless...was your question not answered?
Thanks, Carnac the Magnificent, now you're telling me what I did and didn't do...I may not have used those exact search terms, so I didn't find the results you found. But, then again, it didn't occur to me to use those exact terms. And since you're such a mind reader, you'd know that I've been to that site many times, and I still couldn't find what I was looking for. Again, I probably didn't know the best place to look... Your first solution is absolutely NOT what I'm looking for. Tell me how/if you can include your 2nd solution in an IF condition, and I'll let you know if it's what I'm looking for...
Why would I after you insulted the only person who helped you? Figure it out yourself. The answer is there and should be quite obvious.
So you didn't do your research either.... Word of advice, next time, come in with a better attitude and at least imagine that the question poser did some research on his/her own. Especially if that person doesn't usually ask that type of question. Well, don't you worry about it anymore, I can always seek assistance from someone who doesn't make assumptions...
I gave you 2 options. The second one is to detect if a number is with in a string. All you had to do was swap the functions. See below: $blah = "Test to see if the number 25 will be detected"; if (preg_match("/[0-9]/", $blah)) { print "blah contains a number in it\n"; } else { print "blah does not contain a number in it!\n"; } PHP: