While working on a web accessibility project, I came across this online contrast ratio checker:
http://leaverou.github.io/contrast-ratio/
It lets you enter background colour and text colour (as RGB, hex, HSLA, colour names, etc.), and calculates the contrast.