In my previous post, I talked about input-masking to help ensure the quality of the inputs from the user. Information such as phone numbers and ZIP code can be masked because format is anticipated well in advanced. There are certain types of inputs though that are tough or impossible to mask. Take the email address for example: masking is not applicable (or cumbersome) to implement because there are so many formats that you can apply to an email address, the lengths are variable, and some special characters can be inserted anywhere before the @ sign.
Some classes of data are best validated using regular expressions (or regex). Email address is typically validated using regex. Another field or data-element similar to email address in the way you validate it is the URL (Web sites, etc.)
The OOTB SharePoint forms for the lists (NewForm.aspx and EditForm.aspx) will validate many things. For example, you can make a field be a required field and the OOTB forms will make sure the user input something. Also, when you specify a SharePoint column to be of type “something other than text” (types such “Numbers” and “Dates”) SharePoint will enforce validations on those fields as well. What’s the problem with email addresses and URLs in OOTB SP forms? They are treated as text and the values’ correctness are not enforced. Here’s an example:
You can type in “asdf” on the email address field and it will be okay for the form. That’s not right! So let’s “tweak” the SharePoint forms to make them validate email address.
Next, open-up the SharePoint Site and edit the list’s NewForm.aspx or EditForm.aspx in SharePoint Designer. In this example, we are editing the Contacts List EditForm.aspx. You want to look for the table element whose ID is onetIDListForm. Insert the following code just below the table.onetIDListForm element (notice that we’re simply extending the source code from the previous post):
After the code snippet is inserted into the form, the SharePoint Contact form will now ensure that the inputs conform to the email address field: