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

  • Home
  • SEARCH
  • 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 8935809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:04:40+00:00 2026-06-15T10:04:40+00:00

I have a function isValid that is responsible for searching for spaces in all

  • 0

I have a function “isValid” that is responsible for searching for spaces in all variables provided. I want the function to return true if none of the variables contain spaces. Would this be the right approach?

return !(strpos($this->email, " ") || strpos($this->confirm_password1, " ") || strpos($this->handle, " ") || strpos($this->phone, " "));
  • 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-06-15T10:04:41+00:00Added an answer on June 15, 2026 at 10:04 am

    In order for it to be easily maintainable I would do something like the following:

    public function isValid()
    {
        $properties = array(
            'email',
            'confirm_password1',
            'handle',
            'phone',
        );
    
        foreach ($properties as $property) {
            if ($this->containsSpace($property)) {
                return false;
            }
        }
    
        return true;
    }
    
    private function containsSpace($property)
    {
        return !(strpos($this->$property, '') === false);
    }
    

    Note the === false as check for strpos(). Demo: http://codepad.viper-7.com/0ZgNZq.

    Note that this only checks for spaces and not possible other whitespace characters. If you want to check for other whitespace characters I would suggest to use a simple regex:

    private function containsSpace($property)
    {
        return (bool)preg_match('/\s/', $this->$property);
    }
    

    And finally if you really want to do it your original way I would do something like:

    public function isValid()
    {
        return strpos($this->email, " ") === false && strpos($this->confirm_password1, " ") === false && strpos($this->handle, " ") === false && strpos($this->phone, " ") === false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function getCartItems in cart.js and I want to call that function in
I have a controller object that's like: MyApp.objController = Ember.ArrayController.create({ init: function(data) { data.isValid
I have this function: public bool IsValidProduct(int productTypeId) { bool isValid = false; if
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function Start() that is fired on ready. When I click on .ExampleClick
I have this function I have to implement: protected override ValidationResult IsValid( Object value,
i have an array of objects, and these objects all have an 'isvalid' attribute.
I have a function that I'm calling that validates a recaptcha, and then depending
i have textbox controls that are created dynamically in the ASP.NET. I want to
I have a login widget that is a partial view that I want updated

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.