document upload check

There is a smart service in my interface known as document upload . When i am uploading any document , it should be in pdf or word format , basically I need to check that User can only upload a pdf or word document . If the user uploads document of different type it should throw the error . 

how to achieve this please explain or give some code snippet if possible .

Thanks in advance !

  Discussion posts and replies are publicly visible