Javascript Pattern Matching

I am looking to create a function to allow one to create custom slideshow. Between two select boxes one can pick the images in the order they like them played. The pattern I am looking for is that all images must be accounted for before you can submit.

Select Box A
Contains all the available images that you can choose from. For this example lets say there are 20. image1.jpg through to image20.jpg. All files are named image1.jpg, image2.jpg, … photoN.jpg

Select Box B
Contains the images you would like to add to the custom slideshow and as you select the images a function is called each time to check the pattern to make sure an image isn’t missing.

Pattern Allowed Example
The following images were selected image1.jpg, image2.jpg, image3.jpg, image5.jpg and image4.jpg to create a five image slideshow. There are five images counted and all are accounted for; submit button active.

Pattern Not Allowed Example
The following images were selected image1.jpg, image2.jpg, image3.jpg, image5.jpg and image6.jpg to create a five image slideshow. There are five images counted but image4.jpg is not in the list; submit button not active until added.

The concept is that if five, six, ten or even all images are selected the order doesn’t matter but all images must be there according to the count.

I started with the following expression but that isn’t working… any suggestions?


var disable = 0;
for (i = 0; i < document.getElementById('custom').options.length; i++) {
 var pattern = /image1/;
 if (!pattern.test(file)) {
  //alert('failed');
  disable = 1;
 }
}