Jump to content

Form Validation: Test for Numbers Only


AndrewAK

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...