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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:17:22+00:00 2026-05-26T23:17:22+00:00

I need to validate a textarea using the plugin jQuery Validate, to do that

  • 0

I need to validate a textarea using the plugin jQuery Validate, to do that I use a regex and I add a method to the plugin:

$.validator.addMethod(
    "regex",
    function(value, element, regexp) {
        var check = false;
        var re = new RegExp(regexp);
        return this.optional(element) || re.test(value);
    },
    "No special Characters allowed here. Use only upper and lowercase letters (A through Z; a through z), numbers and punctuation marks (. , : ; ? ' ' \" - = ~ ! @ # $ % ^ & * ( ) _ + / < > { } )"
);

Then in the options I add the regex:

comments:{
    required: true,
    maxlength: 8000,
    regex: /[^A-Za-z\d\-\=\~\!@#\%&\*\(\)_\+\\\/<>\?\{\}\.\$‘\^\+\"\';:,\s]/
}

This “works” in a certain way, it does detect the invalid characters and displays the message, the problem is it only works when the special characters are the only ones in the box, for instance:

| `` ° ¬ // This shows the error message but...
test | // This won't show the message

So if one allowed character is there then the validation just stops working. Am I missing something?

P.S. I’m pretty sure this has something to do with the plugin ’cause I’ve tested the regex with just javascript and it works well.

  • 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-26T23:17:23+00:00Added an answer on May 26, 2026 at 11:17 pm

    rather than testing for the presence of the special characters, test for only presence of valid characters

    regex: /^[A-Za-z\d=#$%...-]+$/
    

    Replace ... with all the special characters you want to allow. In the example above, #, $, %, and - would be allowed. Note: you don’t have to escape (most) of the characters inside of the [].

    If you’d like to allow a -, it needs to be the last character otherwise regex tries to parse a range. (e.g., [a-c] matches a, b, and c. [a-c-] matches a, b, c, and -)

    Also, if you’d like to allow a ^, it cannot be the first character otherwise regex treats this as a sort of not operator. (e.g., [^abc] matches any character that’s not a, b, or c)


    In your example above, the complete regex might look something like this

    regex: /^[A-Za-z\s`~!@#$%^&*()+={}|;:'",.<>\/?\\-]+$/
    

    Explanation

    NODE                     EXPLANATION
    --------------------------------------------------------------------------------
      ^                        the beginning of the string
    --------------------------------------------------------------------------------
      [A-Za-                   any character of: 'A' to 'Z', 'a' to 'z',
      z\s`~!@#$%^&*()+={}|     whitespace (\n, \r, \t, \f, and " "), '`',
      ;:'",.<>/?\\-]+          '~', '!', '@', '#', '$', '%', '^', '&',
                               '*', '(', ')', '+', '=', '{', '}', '|',
                               ';', ':', ''', '"', ',', '.', '<', '>',
                               '/', '?', '\\', '-' (1 or more times
                               (matching the most amount possible))
    --------------------------------------------------------------------------------
      $                        before an optional \n, and the end of the
                               string
    

    check it out!

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

Sidebar

Related Questions

i need to validate address1 , address 2 and city using jquery regex.. Used
I'm looking to validate the length of a textarea using a regular expression validator.
I have a textarea in which I need to validate that at least one
I'm using CKEditor on a textarea and the jQuery validation plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-validation/ )
I am doing validation using ValidationEngine plugin. But I need to validate a text
I need to validate input using JavaScript and jQuery when someone submit my newsletter
I need to validate the email address of my users. Unfortunately, making a validator
I need to validate this simple pick list: <select name=<%= key %>> <option value=ETC
I need to validate an XML agaist a schema. I tried XML::SAX::ParserFactory; XML::Validator::Schema and
I need to validate a basic authorization header that is being sent to my

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.