views:

409

answers:

2

I cave created a custom list in sharepoint (created and provisioned to the 12 hive)

how can i perform validation on certain fields of the list when a new list item is added?

i think i can do it through the "itemadding" event reciever, but is there a more elegant sharepoint way?

eg i just want to check an email field has a valid email format.

+4  A: 

I think you have to options. As you have already mentioned using a event receiver would be one way. But I think a more elegant and above all a more SharePoint like way would be implementing your own custom field type and field control.

This will give you the option to validate the mail address before any event receiver is triggered and to react with an validation message to the user giving him the option to correct his input.

Flo
+1  A: 

You could go with validation on the client using JQuery if you have the id or a css class on the rendered textbox for the email input.

Johan Leino
Should make clear though that with Javascript validation you do make it possible for users to bypass that validation. This may not be a problem for your use but something to be aware.
Ryan