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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:39:43+00:00 2026-05-11T17:39:43+00:00

Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some

  • 0

Background: Our web app uses the jquery.constrain.js plugin to handle data entry in some text boxes, to only allow valid characters to be added. This plugin allows various constraints upon the data, using regular expressions, whitelist/blacklist characters, etc. Until today, we were running the 1.0 release of this plugin, unmodified.

I noticed a few days ago that some of the text boxes still allowed invalid data entry. For example, a numeric-only textbox allowed alpha characters, etc. It also displayed a javascript error “Object doesn’t support this property or method”. I tracked it down to the following function in the jquery.constrain plugin.

    function match(item, input, e) {
        var arr = item.chars.split("");
        for (var i in arr) {
            var token = arr[i];
            if (token.charCodeAt(0) == e.which) {
                return true;
            }
        }
        if (item.regex) {
            var re = new RegExp(item.regex);
            if (re.test(String.fromCharCode(e.which))) {
                return true;
            }
        }

        return false;
    };

Debugging through this block of code, I determined the following:

  • item is an object with two string properties: chars and regex
  • item.chars is an empty string (“”) at the time of failure.
  • arr, the result of item.chars.split(“”) is, as expected, an empty array.

Here’s where it’s weird. Even though arr is an empty array, the for loop assigns a valid value to i. The value is “remove”. So we drop into the loop. token is obviously null, because arr[“remove”] is null. So token.charCodeAt(0) throws.

I corrected the error by adding an if statement around the for loop, as follows:

        if (arr.length > 0) {
            for (var i in arr) {
                var token = arr[i];
                if (token.charCodeAt(0) == e.which) {
                    return true;
                }
            }
        }

However, I’m completely baffled as to why this was even necessary – is this an IE bug, a bug in the plugin, or am I just holding my breath wrong when I compile the app?

  • 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-11T17:39:43+00:00Added an answer on May 11, 2026 at 5:39 pm

    You should never use for(i in arr) to loop over Arrays. If scripts add methods to the Array prototype these too will be iterated using the for(i in arr) loop. This is probably what is causing your errors. You probably have added a script that modifies the Array.prototype chain.

    Also read here under “Why you should stop using for…in to iterate (or never take it up)”
    http://www.prototypejs.org/api/array

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

Sidebar

Ask A Question

Stats

  • Questions 316k
  • Answers 316k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Of course a database can have relationships like that: Users… May 13, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer You want ItemsControl. It has an Items property and its… May 13, 2026 at 11:31 pm
  • Editorial Team
    Editorial Team added an answer If you want any further granularity to your timing than… May 13, 2026 at 11:31 pm

Related Questions

Visual Studio is x86 until at least the 2010 release comes around update: this
I didn't get any responses from the asp.net forum, so I thought I'd try
We are using SVG in our web app and we need to allow users
Background So, I'm working on a fresh iteration of a web app. And, we've

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.