Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We have a column of type "E-Mail" and we'd like to attach validation to it so it conforms to the normal regular expression email validations at a specific domain. Is this possible without writing a web part in Visual Studio? Thank you.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

This codeplex project allows you to add regular expression validation to fields

Codeplex - SharePoint Custom Field Type - Regular Expressions

Be very careful trying to validate email addresses using RegEx though (either through this tool or javascript) - its seems like a ideal candidate for regex until you get into the details and there are a lot of samples out there that are wrong.

For example :-

  • Hardly any one will accept apostrophes in the email - yes o'callahan@tld.com is valid!
  • Many of the example out there will not accept bob@tate.museum TLD and this will only become unmanageable now that the restrictions on creating TLD's have been relaxed.
share|improve this answer
add comment

Other methods you can use:

  • Create a validation formula in the List Settings / Validation Settings.
  • Add some script to your forms to validate on the blur event or in the PreSaveAction

I prefer using script on the blur event because I can give immediate feedback to the user, as they are used to on other modern Web sites.

share|improve this answer
    
Thanks, Marc. I didn't know you could do that. –  Alex C Jul 11 '11 at 11:40
1  
I should have mentioned one other option, which is probably more the party line: a custom field type. I still like the script option better from a UX perspective. –  Marc D Anderson Jul 11 '11 at 12:26
    
You could actually combine the two - a custom field type that uses javascript to do the validation client side as well as server side. –  Ryan Jul 11 '11 at 14:56
add comment

This link gives you two different options. One that involves inserting a hidden web part in the EditForm for the list, and using JQuery to do the actual RegEx validation. Another option is to go with the third-party tool Christian refers to in the article.

share|improve this answer
    
Very nice. Thanks, Biilmann. –  Alex C Jul 11 '11 at 11:40
    
Yes, of course - as Marc points out below - the built-in validation. I just tried it; a validation formula like =SEARCH(".",[Email],(SEARCH("@",[Email],1))+2)>0 will check for the "@" and the ".". However, in my setup, my custom error message when the validation fails does not display. SP just displays a standard validation message. Not sure why yet. So UX-wise, this is not the best, so far. –  Biilmann Jul 11 '11 at 13:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.