How can I restrict gameobject from moving beyond line in unity2d

I have this red apple that need to move only inside the green apple line. If it try to move beyond line it will be stopped at the green line and can’ move beyond. How can I do that?

picture for better understand

This is my code I use to move red apple:

Camera mainCamera;
 float zAxis = 0;
 Vector3 clickOffset = Vector3.zero;
 
 // Use this for initialization
 void Start()
 {
 
     mainCamera = Camera.main;
     mainCamera.gameObject.AddComponent<Physics2DRaycaster>();
 
     zAxis = transform.position.z;
 }
 
 public void OnBeginDrag(PointerEventData eventData)
 {
     clickOffset = transform.position - mainCamera.ScreenToWorldPoint(new Vector3(eventData.position.x, eventData.position.y, zAxis));
 }
 
 public void OnDrag(PointerEventData eventData)
 {
     //Use Offset To Prevent Sprite from Jumping to where the finger is
     Vector3 tempVec = mainCamera.ScreenToWorldPoint(eventData.position) + clickOffset;
     tempVec.z = zAxis; //Make sure that the z zxis never change
     /*
     Debug.Log(tempVec.x);
     if (tempVec.x < 90)
     {
         tempVec.x = 90;
 
     }
     if (tempVec.x > 310)
     {
         tempVec.x = 310;
 
     }
     */
     transform.position = tempVec;
 }
 
 public void OnEndDrag(PointerEventData eventData)
 {
 
 }

I haven’t done something like this, but one thing I would try is to restrict the movement based on color. Make a sprite that has the valid area one color and invalid another. Get the new position and check that position on the validity sprite. If it is the valid color, move the object, otherwise don’t. Someone else may have a better option, but I believe this would work. Your validity sprite could be the sprite with the apple showing, or just an inactive sprite that your code will reference but the user won’t see. Hope that helps!