Is that possible to run same code for multiple projects?

Say for eg. we have email field in most of projects and we automated it for validating the proper email id is entered in the email field in Project A, using the same code can we run it for Project B making the function much more efficient.