AndrewAK Posted October 14, 2017 Share Posted October 14, 2017 Here is a snippet of my code. It works fine, but checks for upper and lower case letters. if (empty($_POST["lastname"])) { $lastnameErr = "Lastname is required"; } else { $lastname = test_input($_POST["lastname"]); if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) { $lastnameErr = "Only letters and white space allowed"; } } I need this to check for numbers only IE: 0-9 for a phone number format. Thank you Link to comment Share on other sites More sharing options...
Gabrielphp Posted October 14, 2017 Share Posted October 14, 2017 You can use a php function called is_numeric(). if(is_numeric($var)) { //do stuff } else { //do other stuff } Hope this is what you want. 1 Link to comment Share on other sites More sharing options...
AndrewAK Posted October 14, 2017 Author Share Posted October 14, 2017 Thank you Gabrielphp, that worked perfectly. I tested for the negative. if(!is_numeric($phonenum1)){ $phonenum1Err="Only numbers0-9"} 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now