Keeping a gameobject within certain 3D boundaries

I have a game that spawns multiple gameobjects (at the moment, chairs) and I want to let the player move the chairs within a room. The chairs must not go out of the room. I’m using a drag and drop script and also a raycast to keep the chair stuck to the ground.

void OnMouseDrag()
    {

        Plane plane = new Plane(Vector3.up, new Vector3(0, 0, 0));
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        float distance;
        if (plane.Raycast(ray, out distance))
        {
            transform.position = ray.GetPoint(distance);
        }



        if (Input.GetKeyDown(KeyCode.Q))
        {
            transform.Rotate(0, 15, 0);
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            transform.Rotate(0, -15, 0);
        }
        if (Input.GetKeyDown(KeyCode.Delete))
        {
            Destroy(this.gameObject);
        }
        //if (Input.GetKeyDown(KeyCode.T))
        //{
        //    GetComponent<Renderer>().material.color = new Color(0, 0, 0);
        //}

    }

Empty gameobject that acts as parent to the chair with sticktoground script attached to it

void Update () {
        
        RaycastHit hit;
        if(Physics.Raycast(this.gameObject.transform.position, Vector3.down, out hit))
        {
            this.gameObject.transform.position = hit.transform.position;
        }
	}

In short, what methods can I use to keep the chairs from exiting the room.

I did something similar (a bit more complex) for a project. This is the code I used:

public static bool IsInBounds(Bounds obj, Bounds area) {
    return obj.min.x > area.min.x && obj.min.z > area.min.z && obj.max.x < area.max.x && obj.max.z < area.max.z;
}

I used this to determine if an object could be placed. The user still could drag an object outside the area, but if he dropped it there, it jumped back to its previous position.

I also had a function to construct an AABB for compound objects with more than one MeshRenderer, if you need that (requires Linq):

Bounds GetMaximalBoundingBox(MeshRenderer[] boundingBoxes) {
	float minx = float.MaxValue, maxx = float.MinValue, miny = float.MaxValue, maxy = float.MinValue, minz = float.MaxValue, maxz = float.MinValue;

	foreach(Bounds bounds in boundingBoxes.Select(r => r.bounds)) {
		miny = Mathf.Min(bounds.min.y, miny);
		maxy = Mathf.Max(bounds.max.y, maxy);

		minx = Mathf.Min(bounds.min.x, minx);
		maxx = Mathf.Max(bounds.max.x, maxx);

		minz = Mathf.Min(bounds.min.z, minz);
		maxz = Mathf.Max(bounds.max.z, maxz);
	}

	Bounds outBounds = new Bounds();

	outBounds.SetMinMax(new Vector3(minx, miny, minz), new Vector3(maxx, maxy, maxz));

	return outBounds;
}