I'm dealing with a really, really weird issue in JavaScript. I'm working on a validator script that loops through a list of fields with jQuery. Each validation is tied to a regular expression on an object that goes like this:


var formats = {

      email: /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g,

      phone: /(?!:\A|\s)(?!(\d{1,6}\s+\D)|((\d{1,2}\s+){2,2}))(((\+\d{1,3})|(\(\+\d{1,3}\)))\s*)?((\d{1,6})|(\(\d{1,6}\)))\/?(([ -.]?)\d{1,5}){1,5}((\s*(#|x|(ext))\.?\s*)\d{1,5})?(?!:(\Z|\w|\b\s))/gm,

      numeric: /(\d+)(((.|,)\d+)+)?/g,

      url: /^((http\:\/\/|https\:\/\/|ftp\:\/\/)|(www.))+(([a-zA-Z0-9\.-]+\.[a-zA-Z]{2,4})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(\/[a-zA-Z0-9%:\/-_\\?\.'~]*)?$/gi

    };


Then I've created a function that given two parameters, the format and the test subject, returns true or false (merely a wrapper of the test method for the RegExp object):


validy.is = function(what, str) {
    return formats[what].test(str);
};


On a jQuery collection, I have INPUT elements with classes named accordingly to each format:


&lt;input type="text" class="field email" id="field-1-1" />
&lt;input type="text" class="field phone" id="field-1-2" />
...


Then, my validation function goes like this:


    formBuilder.validate = function() {
      console.info("=== STARTING VALIDATE ===");

      var isValid = true;
      var allFields = $(".field", formBuilder.form).toArray();
      var validable = ["email","phone","numeric","url"];

      var errors = {
        "email": "Debés ingresar una dirección de e-mail válida (por ejemplo: juanperez@gmail.com).",
        "phone": "Debés ingresar un número de teléfono válido.",
        "numeric": "Debés ingresar un número.",
        "url": "Debés ingresar una dirección Web válida (por ejemplo: www.misitio.com.ar)."
      };

      for (var f = 0; f &lt; allFields.length; f++) {

        var $field = $(allFields[f]);

        console.info($field);
        console.info("--> Field has classes: " + $field.attr("class"));

        for (var v = 0; v &lt; validable.length; v++) {

          var validableClass = validable[v];

          if ($field.hasClass(validableClass)) {

            console.info("--> Validating against " + validableClass + " with value &lt;&lt;" + $field.val() + ">>");
            console.info("--> Test result: validy.is(validableClass, $field.val()) = " + vw.validy.is(validableClass, $field.val()));
            console.info("--> Last value of isValid = " + isValid);

            isValid = isValid && (validy.is(validableClass, $field.val()) ? true : false);

            console.info("--> Value of isValid is now = " + isValid);
            break;

          };

        }

        console.info("** Status of isValid: " + isValid + " **");

        if (!isValid) {

          console.info("--> Invalid field detected");
          //vw.popoverError($field, "Error", errors[validableClass]);
          break;

        };

      };

      return isValid;

    };


The problem with it is that even when the field value is valid and isValid == true, when it does the isValid == isValid &amp;&amp; ... operation, isValid ends up being false.

How can it be possible for a true &amp;&amp; true expression to throw false.

I know there must be some stupidity I can't see, but I can't seem to find it. Can anyone lend a hand on this one?

Thanks!

Update 1

Originally, the line:

isValid = isValid &amp;&amp; (validy.is(validableClass, $field.val()) ? true : false);

was

isValid &amp;= validy.is(validableClass, $field.val();

Update 2

At some point, apparently the test method is returning 1 or 0 instead of true or false. But I can't pinpoint the exact moment when it happens.

Update 3

So it turns out that I was misusing the &amp;= operator as mentioned in the comments. But...

isValid = isValid &amp;&amp; validy.is(validableClass, $field.val());

...returns false when isValid == true and validy.is returns true independently.

Update 4

Changed the validy.is definition according to answer by CaffGeek:


    validy.is = function(what, str) {

      return !!formats[what].test(str);

    };


It had no effect, unfortunately.


Question: Grouping by day + events spanning several days
Answer: Make 2 or 3 computed view fields (which will require some php):


1field for day of event
1 or 2 fields for start time and end time dates.


You can group the View output by the first field. Then create the event time range by inlining the 2 other fields.

With these 3 pieces of info the calendar should be able to see the start and end datetimes and make a line representing the event duration.