You need a prime test function. For small numbers, a modulo test inside a loop is good enough. Before you code it, have a look in your math library, it might already exist.
To test if a number has 2 as one of its digits, convert the number into a string, then search for a "2" inside the string.
A list of prime numbers that contain a 2 is not something where you can apply a simple formula. You need a loop, and it will slow down the higher you go.
If you are trying to generate a list, and you suspect there is a formula, generate the first 7 or so numbers by hand, then type them into the online encyclopedia of integer sequences. There's a good chance that someone has discovered it. Great web site.