I want to put a limit on the edges of the screen for dragable objects

// Hi, my code is working fine but I want put a limit on the edges of the screen so that the dragged object don’t go outside of the screen. How do I do that? Here’s my code.

void OnMouseDown()
{
if (IsDragable == true)
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);

        offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, 0, screenPoint.z));
    }
}

void OnMouseDrag()
{
    if (IsDragable == true)
    {
        Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, 0, screenPoint.z); 

        Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
        transform.position = curPosition;
    }
}

After that code, you could simply put something like

if(curPosition.x>maxPositionX)
{
    curPosition.x=maxPositionX;
}
if(curPosition.x<minPositionX)
{
    curPosition.x=minPositionX;
}

if(curPosition.y>maxPositionY)
{
    curPosition.y=maxPositionY;
}
if(curPosition.y<minPositionY)
{
    curPosition.y=minPositionY;
}

And simply define the min and max variables to your hearts content. Keep in mind you may need to take multiple resolutions into account, depending on your platform(s) of choice. Use this reference to help with that if needed: