In SharePoint Lists and libraries, we have multiple metadata columns which are used for taking inputs from the users. We need some actions for checking and verifying the submitted data  for accuracy on the list form. We call them field validation where we can mark few fields required and can have few fields types where chances of invalid entries are very low like choice field, Date field, people picker etc.

There could be a custom requirement for validations on text fields, like validation on a text field. Today I am taking example of a Student ID number which will have a specific format “NAAANNNNN” (N-Number and A-Alphabet) and we will apply a custom field validation on it.

Column Validation

There are two types of validations available in SharePoint list, Column Validation and List Validation. I will discuss about List based validation in next blog post.

I have created a list for Students, added few columns including Student ID column. I have added Student ID as single line text column.

Now you need to Edit the list column. You can go to list settings à click on Student ID column or can also access it directly from list view as shown below:

Add Custom Validation

Scroll down on column settings and go to column validation, add the validation formula there, in my case I have used the below column validation.

=AND(LEN(Student ID)=9,ISNUMBER(VALUE(MID(Student ID,1,1))),NOT(ISNUMBER(VALUE(MID(Student ID,2,3)))),ISNUMBER(VALUE(MID(Student ID,5,5))),AND(MID(Student ID,2,1)>="A",MID(Student ID,2,1)<="Z"),AND(MID(Student ID,3,1)>="A",MID(Student ID,3,1)<="Z"),AND(MID(Student ID,4,1)>="A",MID(Student ID,4,1)<="Z"))

Add the user message and save the changes on the list

Test Validation

Now add a new item to the list and if entered value is not in proper format, you will get the validation failed message on the list form.

Adnan is six time Microsoft MVP (Since 2015) with over 16 years of extensive experience with major expertise on SharePoint, SharePoint based development, Microsoft 365, Microsoft Teams, .Net Platform and Microsoft BI. He is currently working Sr Microsoft Consultant at Olive + Goose. He is MCT Regional Lead for Pakistan Chapter since 2012. He is working on SharePoint for past 12 years and worked on different intranet/intranet solutions for private & govt. sector majorly in United states and Gulf region and have experience of working with multiple Fortune 500 companies. He is a trainer, technology evangelist and also speaks in community forums.

Leave a Reply