0

Here is my third mis-guided attempt:

var check = {
  pattern : patterns =
    {
    name: /^[a-zA-Z-\s]{1,20}$/,
    email: /^[a-zA-Z0-9._(-)]+@[a-zA-Z0-9.(-)]+\.[a-zA-Z]{1,4}$/,
    pass: /.{6,40}/,
    url:  /^[(-)\w&:\/\.=\?,#+]{1,}$/,
    aml:  /<(.+)_([a-z]){1}>$/
    };  
  };

2 Answers2

2

If this is the structure you want:

Object
  pattern: 
    Object
      aml: /<(.+)_([a-z]){1}>$/
      email: /^[a-zA-Z0-9._(-)]+@[a-zA-Z0-9.(-)]+\.[a-zA-Z]{1,4}$/
      name: /^[a-zA-Z-\s]{1,20}$/
      pass: /.{6,40}/
      url: /^[(-)\w&:\/\.=\?,#+]{1,}$/

The right syntax is :

var check = {
  pattern : {
    name: /^[a-zA-Z-\s]{1,20}$/,
    email: /^[a-zA-Z0-9._(-)]+@[a-zA-Z0-9.(-)]+\.[a-zA-Z]{1,4}$/,
    pass: /.{6,40}/,
    url:  /^[(-)\w&:\/\.=\?,#+]{1,}$/,
    aml:  /<(.+)_([a-z]){1}>$/
    }
  };
steveyang
  • 9,178
  • 8
  • 54
  • 80
  • 10 minute wait on setting the answer –  Nov 16 '11 at 02:19
  • @steven.yang the outer object is not an associative array in your sample, but that is what is being asked for – sissonb Nov 16 '11 at 02:20
  • @sissonb what do you mean by 'outer object is not an associative array'? I think associated array is expressed as object in javascript. [A reference](http://www.quirksmode.org/js/associative.html). The difference is in the notation - either through `foo.bar` or `foo[bar]` – steveyang Nov 16 '11 at 02:27
  • @steven.yang associated array means key => value. http://en.wikipedia.org/wiki/Associative_array Your inner object has a key of pattern, the object containing this associative array has no key. – sissonb Nov 16 '11 at 02:36
  • @sissonb Thanks for the clearance. So the concept of **object** covers **associated array** in javaScript? An associated array must be an object, an object isn't necessarily an associated array? In my example code, I think the outer object has the key **pattern**, does it count an associated array? – steveyang Nov 16 '11 at 02:41
  • @steven.yang Yeah, not a big deal. This is probably a cleaner structure anyways. As Demian pointed out it's a pretty verbose structure to nest associative array. – sissonb Nov 16 '11 at 02:44
1
var check = {
    pattern: {
        patterns: {
            name: /^[a-zA-Z-\s]{1,20}$/,
            email: /^[a-zA-Z0-9._(-)]+@[a-zA-Z0-9.(-)]+\.[a-zA-Z]{1,4}$/,
            pass: /.{6,40}/,
            url:  /^[(-)\w&:\/\.=\?,#+]{1,}$/,
            aml:  /<(.+)_([a-z]){1}>$/
        }
    }
};

http://jsfiddle.net/dbrecht/NcbHZ/

...Although your naming convention (pattern.patterns) doesn't really make sense, unless there's something I'm not seeing there.

Demian Brecht
  • 21,135
  • 5
  • 42
  • 46