Take the 2-minute tour ×

I have an interactive/editable table that does a number of things when a cell value is changed using onChange="myfunction". The problem is that I need to have a few validations:

  1. maxlength = 1
  2. only letters ^[a-zA-Z]+$
  3. cannot be blank...require = true

However I fear that due to using onChange I may not be able to achieve this.

Here is a working example of my table: http://jsfiddle.net/JEAkX/32/

Here is the jQuery validator code I am hoping to get to work:

    function(value, element) {
        return this.optional(element) || /^[a-zA-Z]+$/.test( value );
    alert("Bad Value!")
$(document).ready(function() {
        rules: {
            cell: {
                legalValue: true,
                required: true,
                maxlength: 1

Is it possible to make this work given my current setup using onChange? If not what direction would you recommend taking to converting to a system that would allow for this validation.

If I stay with onChange do I need to great a global array to house the values of the table in the case that someone enters something incorrect and the value is reverted so the table doesn't change?

share|improve this question
add comment

1 Answer

just had a look at your sources, I'm not sure I understand what is your problem, but your code has one mistake:

<script type="text/javascript" scr="http://view.jquery.com/trunk/plugins/validate/jquery.validate.js"></script>

should be

<script type="text/javascript" src="http://view.jquery.com/trunk/plugins/validate/jquery.validate.js"></script>

not pushing you to solve the puzzle what's the difference is, I could say that path to script file is specifying using src attribute rather than using scr. After I changed that, when I enter "4" in any field, I get warning message about mistake etc. Also I can't enter few characters... So look like it works.. Was it the problem, or I didn't get your question?

share|improve this answer
add comment

Your Answer


