Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6027825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:38:56+00:00 2026-05-23T04:38:56+00:00

Stupid question. I’ve got a project that I’m working on in PHP; it’s a

  • 0

Stupid question.

I’ve got a project that I’m working on in PHP; it’s a registration form for a customer that will eventually write to a MySQL database. I’ve got the form doing data validation for the fields involved, and I’m already using some of PHP’s builtin filter functions.

However, I’ve got quite a few fields that I need to validate for different purposes – for example, I’ve got email addresses and web addresses to verify (which are covered in the filter package), but I’ve also got to verify phone numbers, zip codes, addresses, and names (which should only match a certain character set).

Right now, my solution consists of a lot of if-then statements to verify a field. For instance, for zipcode, I verify whether it’s numeric with ctype_digit, and then I use strlen to check the length. (I could encapsulate everything inside an object – and I will probably do so once I’ve got everything working as it actually should – but that’s a little ways away.) Does anyone know of a third-party class that will do stuff like this? Or, if not, at least a way to validate specific input types without resorting to if statements based on the input name. since it’s really not scalable?

If I ned to edit this question or add anything, let me know. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:38:57+00:00Added an answer on May 23, 2026 at 4:38 am

    Check out FILTER_VALIDATE_REGEXP. It lets you do your own custom validations.

    $filter_zip_options = array( "options" => array( "regexp" => "/^[0-9]{5}$/" ) );
    var_dump( (bool)filter_var( "99999", FILTER_VALIDATE_REGEXP, $filter_zip_options ) ); //bool(true)
    var_dump( (bool)filter_var( "991999", FILTER_VALIDATE_REGEXP, $filter_zip_options ) ); //bool(false)
    

    If you hate regex, you can also use FILTER_CALLBACK.

    //To use a closure as an in place callback you need PHP 5.3
    var_dump( filter_var( "Kendall", FILTER_CALLBACK, array( "options" => function( $input ) {
        //check if it's 1 or 2 words
        if( count( explode( " ", $input ) ) > 2 )
            return FALSE;
    
        return "Hello world $input";
    } ) ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Stupid question, this code: <?php $variable = system(cat /home/maxor/test.txt); echo $variable; ?> with file
Sorry for totally stupid question, but the situation is that I have to make
It's just a stupid question that I had this morning : Can we use
This is obviously a stupid question. I am coding in Eclipse both on Mac
This might be a stupid question but if there's a better or proper way
This maybe a stupid question, but as I can not easily undo my change
This might be a stupid question but I just wanted to make sure... If
This might be a stupid question, but I can't for the life of me
This might seem like a stupid question I admit. But I'm in a small
Sorry if this sounds like a really stupid question, but I need to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.