views:

94

answers:

5

I saw here square brackets that are used in class names:

<input class="validate[required,custom[onlyLetter],length[0,100]]" name="firstname" type="text" />

What does this means ?

+1  A: 

Nothing. Brackets are a legal character for class names with no special meaning whatsoever.

Jörg W Mittag
But they do have meaning in css files, so best not to use class names like this for styling. This stuff should probably go in a custom validation attribute.
Douglas
+6  A: 

That is most likely used by some sort of validator or validation library. The class here means that validate this field denoted by validate keyword and then:

required it is required feild
custom validation type; allow only letters
length should be between 0 to 100 chars

Well, this information is used by the jQuery validation library you posted the link to :)

Sarfraz
Thanks for the explanation !
Misha Moroshko
@Misha Moroshko: You are welcome :)
Sarfraz
+1  A: 

In standard HTML, they have no particular meaning. It's just more text.

To the jQuery Validation plugin, they do.

James Curran
+1  A: 

There is no particular rule within a class name. In your example they are almost certainly being used by a JavaScript validation framework. This is because in HTML you can't simply add your own attributes to tags, therefore the validation framework is exploiting the fact that CSS class names can contain such characters in order to 'store' the validation rules within the class name. There won't actually be any corresponding class in the style-sheet - this is just a trick to work around the limitations of HTML.

Dan Diplo
Actually, in HTML5 you *can* add your own attributes, as long as they begin with the string `data-`. They were added specifically to make such abuses of classes unnecessary.
Jörg W Mittag
+1  A: 
Jevgeni Bogatyrjov
@JB: Thanks a lot.
J. Bruni
While this information is correct, it is not the context the OP asked for... Both square bracket syntaxes have nothing in common which each other.
hurikhan77