Jump to content

Form Validation: Test for Numbers Only

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...