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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:18:10+00:00 2026-06-08T13:18:10+00:00

I am trying to validate an email field. I took this regex from somewhere

  • 0

I am trying to validate an email field. I took this regex from somewhere on here for and I used it on another form I made and it works fine. Yet when I use it now its not matching.

All I am trying to do is to check the email and if it is good then log it in the proper field in the db.

For the sake of not pasting a bunch of stuff… I have stripped out the problem lines and going to pseudo code next few lines.

Essentially, vars are these:

$theEmail = $_post email from first page here
$regEx ='#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si';

and my php is this

//essentially other field validation will go here...for now testing only empty.
    if(!empty($theEmail)){
        if (preg_match($regEx, $formEmail)) {
            //send it through to db.

        } else { //error stuff here }
    }

essentially, this never comes true. The email never validates no matter what I do and as I said I wrote another more complicated form that validates data just fine

Not sure what is going on.

  • 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-08T13:18:13+00:00Added an answer on June 8, 2026 at 1:18 pm

    /^[a-z0-9.!\#$%&\'*+-=?^_{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$/

    I removed the first # and ending #si, and took out the / from the = since it was giving me problems. This generates a match on my e-mail address here:

    <?
    $theEmail = 'me@davebel.com';
    $regEx ='/^[a-z0-9.!\#$%&\'*+-=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$/';
    print_r(preg_match($regEx, $theEmail));
    ?>
    

    Though this regex is very complex for something like e-mail validation- I would recommend trying to refine it and fine-tune it before putting it into production.

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

Sidebar

Related Questions

I can't figure out where I'm going wrong here. Trying to validate an email
I'm trying to validate uniqueness of an entity submitted from a form by using
I am trying to validate user input from a form before submit but it
im trying to validate my form, but for some reason the SSN field wont
Trying to validate the email field in a rails devise app with a word
Hi I am trying to validate an email using regular expresions.This is my code:
Possible Duplicate: Validate email address in Javascript? I am trying to use this javascript
I am trying to validate email using javascript but for some reason it is
While trying to validate form data on my page i get the following error:
I am trying to validate some form fields but it always errors out on

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.