troubleshooting Question

PHP: Best practice for validating Option Select

Avatar of trevor1940
trevor1940 asked on
HTMLPHP
4 Comments2 Solutions139 ViewsLast Modified:
I have a html form with an option select for choosing a country name see sample code bellow

I'm wondering how to validate this part of the form in PHP using filter input

filter_input(INPUT_POST, "Country", FILTER_VALIDATE_INT);

Will detect if no country has been selected because the value is 1
how would I validate a proper 3 figure country code

Is regex the best way or test for string length?  


<div >
 <select name="Country" >
  <option selected value=1>Please select</option>
  <option value="BRA">Brazil</option>
  <option value="NZL">New Zealand</option>
  <option value="SWZ">Switzerland</option>
 </select>
</div>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros