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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:31:13+00:00 2026-05-23T16:31:13+00:00

Hello I have a question with javascript form validation and regular expressions. Below is

  • 0

Hello I have a question with javascript form validation and regular expressions. Below is the code I used. I am trying to validate that an address has a number and a letter from the alphabet. This code is for experimentation and does not need to do any ultra secure validation.

Problem is the below code doesn’t seem to work. No matter what I do the alert box tells me I have to enter a valid address. What is wrong. Isn’t the regular expression searching the value and finding false? Even if I enter a normal address like 123 Sky Rd. it still outputs Please enter a valid address.

I hope my question is clear. Below is the code to really clarify what is going on. Why is this not valid?

 if (document.customerInfo.address.value == ""){
        msg += "Please enter a valid address\n";
        }
    else if (document.customerInfo.address.value.match(/[0-9]/) != true)
            {msg += "Please enter a valid address\n";}
    else (document.customerInfo.address.value.match(/[abc]/) != true)
            {msg += "Please enter a valid address\n";}
  • 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-23T16:31:13+00:00Added an answer on May 23, 2026 at 4:31 pm

    This code is wrong in a number of ways. First of all, match() doesn’t return true or false. It returns null or an array of matches. Second, your regular expression is looking for either a string of all numbers or a string of all characters and you have a string of both (including spaces).

    What are you really trying to test for?

    A single regex of /[a-zA-Z0-9 ]+/ will allow numbers, letters and spaces, but I don’t know why you’re even checking that. An address isn’t something that can really be checked this way. You can make sure the field isn’t empty, but addresses can take all sorts of forms including characters like # as in Suite #100. I think all you can really do here is check that it’s not empty.

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

Sidebar

Related Questions

Hello JavaScript guru's. I have a simple JS question on how to replace all
I have a question on Javascript and DOM; shouldn't the following code retrieve the
Hello guys I have a question regardless a old code a client needed a
Imagine I have the following: inFile = /adda/adas/sdas/hello.txt # that instruction give me hello.txt
I have a question relative to this code. It should (and it does) display
Here's some question about oop in js (questions in the code below). <html> <script>
Hello fellow drupalers, I have a question about ajax loaded views. Lets say i
Hello I have a c# application that has a button Submit and in the
Dup of Some Basic PHP Questions Hello, I have a heap of tinyint fields
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc

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.