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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:16:47+00:00 2026-06-05T11:16:47+00:00

I’m new to Javascript and I am learning regular expressions and was wondering if

  • 0

I’m new to Javascript and I am learning regular expressions and was wondering if anyone could shed some light on a couple of problems I came across.

I’m writing feedback form which requires validation before sending and I wasn’t quite sure how to include spaces for the address.

I have this code so far, which works as long as I don’t include spaces:

function isAlphanumeric(elem, helperMsg){
    var alphaExp = /^[0-9a-zA-Z]+$/;
    if(elem.value.match(alphaExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

Can I simply insert \w so the expression includes spaces?

Also, I wanted to do an alert which lets the user know the form submission has been successful. Using this code:

if(isAlphabet(firstname, "Please only enter letters for your name")){
if(isAlphabet(surname, "Please only enter letters for your name")){
if(emailValidator(email, "Please enter a valid email address")){
if(isNumeric(phone, "Please enter a valid telephone number")){
if(isAlphanumeric(address1, "Numbers and letters only for address")){
if(isAlphanumeric(pcode, "Please enter a valid postcode")){
{
return true;

}}}}}}}

return false;

Where is the best place to insert the code? I tried after return true, but it didn’t work.

Any tips would be great!

  • 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-05T11:16:52+00:00Added an answer on June 5, 2026 at 11:16 am

    \w does not include spaces, so that won’t work. If you just want to allow a literal space character, then insert it:

    /^[0-9a-zA-Z ]+$/
    

    If you want to allow all kinds of space characters, use \s:

    /^[0-9a-zA-Z\s]+$/
    

    As for placing an alert after return true;, that definitely won’t work; return, as the name suggests, returns from the function. Execution of the function ends there. Just put the alert before the return true.

    You might also consider using && (logical AND) to make things neater there.

    if(isAlphabet(firstname, "Please only enter letters for your name")
    && isAlphabet(surname, "Please only enter letters for your name")
    && emailValidator(email, "Please enter a valid email address")
    && isNumeric(phone, "Please enter a valid telephone number")
    && isAlphanumeric(address1, "Numbers and letters only for address")
    && isAlphanumeric(pcode, "Please enter a valid postcode")) {
    {
        alert('Form submission successful.');
        return true;
    }
    
    return false;
    

    You might also want to reconsider whether you actually want an alert saying the submission was successful. I generally avoid that – if something is successful, it should be obvious.

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

Sidebar

Related Questions

Learning javascript when I came across the concept of prototype. I succeeded in adding
I have just started learning Jquery and am new to writing javascript (I am
I'm fairly new to javascript and I'm just wondering if there is a way
I'm new to JavaScript, and I'm currently learning about the so-called for... in loop.
hello im new and learning javascript. I'm trying to make a program of addition
I am new to javascript and still learning the ropes. I am trying to
I'm learning javascript for a new project. I have seen many tutorials about javascript
I'm learning Javascript as a new language, and I figured a good way to
I just started learning javascript for 2 weeks so I'm pretty new to it.
I'm pretty new to JavaScript, which I am learning on my own. I'm currently

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.