Email validation in SharePoint 2010
-
16-10-2019 - |
Question
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.
Solution
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.
OTHER TIPS
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.
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.