views:

59

answers:

2

I found the jquery validation plugin (http://plugins.jquery.com/project/validate) and thought that this would be a good way to validate my forms on the client side. (I'm also doing server side validation). The plugin want me to specify the validation rule for each field in the class tag. I'm using my class tag for styling my fields, can I specify the rule in some other way?

For example this is how jquery plugin want me to write if I want the field to be required:

<input type="text" id="MyText" class="required" />

I would really like to specify the rule in another tag like:

<input type="text" id="MyText" class="TextStyle" validation="required" />

Is this possible and if so, how?

A: 

You can specify multiple classes for elements separating them with a space:

<input type="text" id="MyText" class="TextStyle required"/>

So that you have both styling and validation.

Agos
A: 

IMHO is is better to keep validation rules away from the HTML:

$('#someForm').validate({
    rules: {
        MyText: {
            required: true
        }
    },
    messages: {
        MyText: {
            required: 'Please fill the MyText field'
        }
    }
});

and just have:

<input type="text" name="MyText" id="MyText" />
Darin Dimitrov