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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:06:12+00:00 2026-06-05T21:06:12+00:00

When a user submit forms,i’m checking empty validation and data validation. For ex:In data

  • 0

When a user submit forms,i’m checking empty validation and data validation.

For ex:In data ,first field is name,i’ll check whether user has entered any other characters else than alpha character’s.if he has entered then will show him an error message.Name should contain minimum of 4 characters and max of 20 characters

I’m using this code but it is not working correctly.How to check the regex.

$validate = array("Category"=>"$productCategory", "Name" => "$productName");

$error = '';

foreach ($validate as $key => $field) {

    if (preg_match('/^[a-z\d ]{4,20}$/i', $$field)) {
       echo $error .= $field;
    }
}

Thanks in advance!

  • 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-05T21:06:14+00:00Added an answer on June 5, 2026 at 9:06 pm

    You have a typo in the preg_match, you type $$field (2x$) instead of $field, your regex is fine it will match:

     - a character between a - z (case insensitive)
    or
     - a digit between 0 - 9
    or 
     - a "space" character.
    

    Update code to answer @Andrius Naruševičius comment

    $validate = array("Category" => $productCategory, "Name" => $productName);
    $error = '';
    foreach ($validate as $key => $field)
    {
        if (preg_match('/^[a-z\d ]{4,20}$/i',$field))
        {
           $error.= $field;
        }
    }
    
    if($error)
    {
        echo $error;
        exit;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ASP.NET Web forms, When a user submit a page, an email
I have several php pages that have forms used to submit data. My typical
I have developed a script for checking that user has selected a valid month
I'm trying to secure the data users submit via forms on my website so
the user needs to provide a list of field/values through a form class FieldForm(forms.Form):
I have a form, when user submit the form, I want to direct the
I have an android app which let the user to submit a form ,
I want to submit my form after a user clicked/touched the checkbox: THE HTML
I want to have multiple multiple choices given to user after the form submit
I have an HTML page with a simple form. When the user clicks submit,

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.