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 8400869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:39:33+00:00 2026-06-09T21:39:33+00:00

I was basically playing around with OOP and was creating a way to validate

  • 0

I was basically playing around with OOP and was creating a way to validate and sanitise input when I started to run into problems sanitising and then performing further validation. What I’m looking for is to take the posted $_POST['name'] data, sanitise the input to remove any numbers and validate that the data left is neither null or numeric characters.

But I cant get the sanitised input saved to $sanitised, It seems to be empty, but when I replace

$sanitised=$fv->noNumbers($_POST['name']);

with

$sanitised=preg_replace('/[0-9]/', '', $_POST['name']);

everything works fine, so I think I’m messing up something in this $sanitised variable.

I wanna learn so either a solution to this or a “you’re an idiot and doing it all wrong” would be much appreciated.

<?php
    class formSanitise {

        public function noNumbers($value) {
            $value = preg_replace('/[0-9]/', '', $value);
        }
        public function isEmpty($value) {
                    return (!isset($value) || trim($value) == '') ? true : false;
        }
        public function isAlpha($value) {
            return preg_match('/[^a-z]/i', $value) ? false : true;
        }
?>

processor.php

<?php
    include('class.formSanitise.php');
    $fv = new formSanitise();

    $sanitised= $fv->noNumbers($_POST['name']);

    if ($fv->isEmpty($sanitised)) {
        $fv->addError('Name', 'Please enter something');
    }
    if (!$fv->isAlpha($sanitised)) {
        $fv->addError('Name', 'Please enter your name');
    }
?>
  • 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-09T21:39:34+00:00Added an answer on June 9, 2026 at 9:39 pm

    You’ll either need to create a return in noNumbers or pass $value by reference.

    Return method:

    public function noNumbers($value) {
                return preg_replace('/[0-9]/', '', $value);
            }
    

    Reference

    public function noNumbers(&$value) {
                $value = preg_replace('/[0-9]/', '', $value);
            }
    

    returning a value means that $value is an entirely different variable, and will be assigned to $sanitized when it’s returned from the function. Passing by reference means that $value is the exact same variable as the one you passed to noNumbers and as such, anything that happens to the variable inside the function will happen to the variable that has been passed in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Completely new to most of this stuff, but basically Im playing around with the
I've just started playing around with android, so pardon me if this is a
I'm playing around a little with dividing up a MVC-site into several assemblies (ran
I just started playing around with the WPF RibbonControl library from Microsoft (October 2010
I'm playing around with a jquery function called ghostType which basically types out text
I'm playing around with https://github.com/elii/Cappuccino-X-Juggernaut , which is basically a juggernaut chat for rails,
I'm learning Java and just started playing around with mysql and am having a
I was playing around with the Google Complete API looking for a quick way
i have some sample code i have been playing around with. Basically im just
Ive been playing around with the entity framework with an idea for creating a

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.