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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:11:23+00:00 2026-05-16T10:11:23+00:00

So, I suck terribly at regex and javascript. As such, when I realized I

  • 0

So, I suck terribly at regex and javascript. As such, when I realized I needed to validate a form field via jquery to ensure that at least one alpha character was used, I decided to ask you fine folks for some help.

I want to allow user to use apostrophes, spaces, dashes, periods, underscores, and alphanumeric chars in this field. They must, however, use at least one alpha character.

Here is the validator method I created, which does everything but ensure that at least one alpha char is used.

 $.validator.addMethod("nameRegex", function(value, element) {
        return this.optional(element) || /[^a-z/g]+/gi.test(value) || !/[^\.\'\:\-_ a-z0-9]+/gi.test(value);
    }, "Name must contain at least one letter.");

Any tips/hints/insights/insults? Thanks everyone!

  • 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-16T10:11:24+00:00Added an answer on May 16, 2026 at 10:11 am

    I have had luck doing a look ahead for the required letter then matching only on valid characters for the minimum length. In my example I use a minimum length of 8 characters with valid characters of apostrophe, space, hyphen, period, underscore, and alphanumeric characters. The ‘\w’ character class is suppose to match underscore and alphanumerics I believe. It seems to work in my tests:

    var r = new RegExp("^(?=([` -.]|\\w)*?[a-zA-Z])([` -.]|\\w){8,}$")
    > r.test('12345678') //all numbers shouldn't work
    false
    > r.test('12345678a') //long enough and one letter should work
    true
    > r.test('12345`_bc') //allow ` _
    true
    > r.test('a12345`_') //shouldn't matter if letter is in front
    true
    > r.test('123a45`_') //shouldn't matter if letter is in middle
    true
    > r.test('12345`_29') //even if special characters no letter should not work
    false
    

    EDIT: I added a ‘?’ after the ‘*’ in the look ahead to make the quantifier non-greedy. Also I should note that I tested this in Chrome and obviously my test cases are not conclusive. I hope this helps though. Another approach is to match zero to many valid characters, at least 1 letter, then zero to many valid characters. Something like:

    var r = new RegExp("^([` -.]|\\w)*[a-zA-Z]+([` -.]|\\w)*$")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The author of this page: http://24ways.org/2011/your-jquery-now-with-less-suck asserts that the jQuery selector $('#id').find('p') is faster
Guys I hate Regex and I suck at writing. I have a string that
I suck at regex, I only managed to get so far preg_match(/http:\/\//, $url) .
To be honest, I suck at regex so much, I would use RegexBuddy, but
I admit, after all these years I suck at regex. I am hoping someone
My English's suck, please understand it. I am a beginner in programming field. What
I need to join tables to do aggregation. I suck at that. Here's my
Are there any jQuery 1.3 animation-transitions that work in both Firefox 3 and IE7?
I have a system that needs to suck up an entire MS SQL database.
I have a loop that is my biggest time suck for a particular function

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.