Hello Abdu
I labbed this up and tested it and yes indeed, in order for two OSPF routers to become neighbors, they must be directly connected, and each must have an interface in the same subnet, and have the same subnet mask on those interfaces.
I hope this has been helpful!
Laz