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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:19:45+00:00 2026-06-16T10:19:45+00:00

I would like to create a regex pattern in javascript for a html text

  • 0

I would like to create a regex pattern in javascript for a html text field that takes an address. So I only want the user to enter [a-z,A-Z,0-9] and only these symbols [,#-.] I also want to prevent the user from sending an empty string and the maximum number of characters to be less than 100.

This is the html <input>:

<input type="text" id="addy" maxlength="100"/>

I’m new to javascript, so I do not know how to create a function that will enable the regex patterns to be adhered to.

Thanks

EDIT

Following the recommendation by kolink I tried this:

 <input type="text" style="width:285px" placeholder="Enter A Precise Address" name="address0" id="address"
     pattern="[ a-zA-Z0-9,#.-]+" maxlength="100" title="Standard address notation only"/>

This now only works if the other <select> have not been selected. Otherwise it does not pick up the pattern attribute. However the exact same code works as expected on jsfiddle: http://jsfiddle.net/peD3t/7/ but not in the browser. This is the code in pastebin: http://pastebin.com/qQGJ4EK5

Thanks

  • 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-16T10:19:46+00:00Added an answer on June 16, 2026 at 10:19 am

    HTML5 gives you the pattern attribute, which allows you to require a certain pattern. In this case, you’d want pattern="[a-zA-Z0-9,#.-]+"

    It doesn’t matter that older browser don’t support this, because you should always validate on the server side.

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

Sidebar

Related Questions

How can I create an XPath expression that works like a regex would, so
I would like to create a Sublime Text 2 Snippet that fills up the
I would like to create a regex in C# that removes a specific character
I would like to know how to create a regex pattern in format: 111.222-3M
I would like to create a function that creates regex matching an arbitrary string
I want to create a regex that parse only links that complies to the
I would like to create a regex to validate customer names. This would be
I would like to create a c++ type that mimic the build-in type exactly.
I would like to create set of strings and below is the only limitation.
I would like to create a class that runs something (a runnable) at regular

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.