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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:03:59+00:00 2026-05-24T21:03:59+00:00

I have been trying to get regular expressions to work in PHP for quite

  • 0

I have been trying to get regular expressions to work in PHP for quite some time now. The problem is that it doesn’t accept things that it should and while accepting text that it shouldn’t. I tried different expressions from the internet since I probably didn’t write them correct myself. It still didn’t work, no mather how trivial expressions I tried so I assumed that there were other things in my code that was causing these problems. I therefor reduce my code to the bare minimum, but still it does not work and I can’t understand why.

What I really want is to check if the text only contains numbers, letters and a few special characters, but to make sure that the expression itself wasn’t the problem, I used the simplest expression I could find; just checking for letters. I have tried many things, like writing the pattern inside the function instead of saving it as a variable etc but nothing helped. This is the code as it looks now, all of it.

<?php

$pattern = "/^[a-z]$/";

if($_POST && !empty($_POST['input']))
{
    if(preg_match($pattern, $_POST['input']))
    {
        echo 'Correct';
    }
    else
    {
        echo 'Wrong';
    }
}
?>

<html>
<body>

<form method="post" action="">
<p><input type="text" name="input"></p>
<p><input type="submit" name="submit"></p>
</form>

</body>
</html>

Help would be greatly appreciated!

  • 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-24T21:04:00+00:00Added an answer on May 24, 2026 at 9:04 pm

    This expression checks for single letter only.
    Change

    $pattern = "/^[a-z]$/";

    To

    $pattern = "/^[a-z]+$/";

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

Sidebar

Related Questions

I have been trying to solve a PHP regular expression problem for awhile now
I have been trying to get this to work for 12 hrs now and
I have been trying to get nServiceBus to work with Ninject 2.0 as the
I have been trying to get this to work correctly and I think I
I have been trying to get my head around some errors I get when
I have been trying to get this jsfiddle to work. So far without luck.
I have been trying to get a2billing to work for the past 4 days
I have been trying to get this to work. Basically I have a search
I have been trying to get this to work for most of the day
This is my first time working with regular expressions and I've been trying to

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.