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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:15:27+00:00 2026-05-29T11:15:27+00:00

I am making an form on my website but I have an problem with

  • 0

I am making an form on my website but I have an problem with 2 regexs.
(I have an PHP regex and an JS regex because I read that javascript only is dangerous)

First is in PHP

$name = mysql_real_escape_string($_POST['name']);
                    if(strlen($name) < 2 || strlen($name) > 20 || preg_match('#[0-9]#',$name))
                    {   
                        echo '<p class="center"> je naam: <b> '.$name.' </b>  bevat cijfers en/of mag niet korter zijn dan 2 tekens en niet langer zijn dan 20 tekens. </p>';                   
                        echo '<p class="center"> <a href="javascript:history.go(-1);">Ga terug</a></p> ';
                    }

this preg_match give’s an error if there are numbers in the name.
The question is I dont want that people have &^*#@ and that things in there name.

What is the correct regex for that.

Next is Javascript

function checkform ( form )
    {
        if (form.name.value == "") 
        {
            alert( "Please enter your name." );
            form.name.focus();
            return false ;
        }

        if (form.email.value == "")
        {
            alert( "Please enter your email address." );
            form.email.focus();
            return false ;
        }

        return true ;
    }

Here I want the same thing and validate that checks emptyness and length and no #$^&!

For email validate I need another regex but i search that one later.

Greeting Jochem

Please edit if you see mistakes.

EDIT:

var re and var regex are email regexs that i found.
But why wont they work kan someone give me an good answer with explination because i am not so good. 🙂

function checkform ( form )
    {
        var rex = /[^a-z]/i;
        var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

        if (regex.test(form.email.value))
        {
            alert( "Please enter your email address." );
            form.email.focus();
            return false ;
        }

        if (rex.test(form.name.value)) 
        {
            alert( "Please enter your name. no numbers or #$^& things allowed)." );
            form.name.focus();
            return false ;
        }

        return true ;
    }
  • 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-29T11:15:27+00:00Added an answer on May 29, 2026 at 11:15 am

    If you only want to accept letters, use /[^a-z]/i. You can use this regex in PHP and in JavaScript.

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

Sidebar

Related Questions

I am making a feedback form for my website using php, I thought that
I have a problem making a select tag in php code dynamic. I'm creating
I am making a website and I have made a form fields like email
i am a beginner in making website, i learned things at msdn only, but
i'm currently making search engine for a website content (only for searching within that
I have a little experience in php and I am making a website for
I need to add a contact form to a website I'm making, and found
Alright, so I'm making a form validation everything is good in this JS, but
I'm making a simple form that is to step through a program iteratively. How
I have a file upload form on my website and would like to add

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.