If by 'text' you mean US-ASCII (like most .c, .cpp, etc files), then just confirm the first 1KB of so of the file is between 32 and 127 (with the exceptions borisbn states, such as \r, \n & \t)
'.txt' files are more complicated - they could be in unicode, so then it becomes a lot more difficult (Unless you just support UTF8, then you can recognise the byte ordering and individual characters easily)
Bookmarks