how to limit jumping

so im new to coding and im making a game and something has been annoying me the past few days is that if i press the jump button over and over he just keeps going up here is the code its a 2d platformer please help
{

//Movement
public float speed;
public float jump;
float moveVelocity;
//Grounded Vars
bool grounded = true;
void Update()
{
    //Jumping
    if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.W))
    {
        if (grounded)
        {
            GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jump);
        }
        
    }

    moveVelocity = 0;

    //Left Right Movement
    if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
    {
        moveVelocity = -speed;
    }
    if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
    {
        moveVelocity = speed;
    }

    GetComponent<Rigidbody2D>().velocity = new Vector2(moveVelocity, GetComponent<Rigidbody2D>().velocity.y);

}
//Check if Grounded
void OnTriggerEnter2D()
{
    grounded = true;
}
void OnTriggerExit2D()
{
    grounded = false;
}

},so im new to coding and i have been trying to make a game and for a few days now i have been stuck on trying to make him only jump once here is my code please help
{

//Movement
public float speed;
public float jump;
float moveVelocity;
public float maxjumps;
public float jumps;
//Grounded Vars
bool grounded = true;
void Update()
{
    //Jumping
    if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.W))
    {
        if (grounded)
        {
            GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jump);
        }
        
    }

    moveVelocity = 0;

    //Left Right Movement
    if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
    {
        moveVelocity = -speed;
    }
    if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
    {
        moveVelocity = speed;
    }

    GetComponent<Rigidbody2D>().velocity = new Vector2(moveVelocity, GetComponent<Rigidbody2D>().velocity.y);

}
//Check if Grounded
void OnTriggerEnter2D()
{
    grounded = true;
}
void OnTriggerExit2D()
{
    grounded = false;
}

}

it looks like it’s all coded right, I think the issue is with

 //Check if Grounded
 void OnTriggerEnter2D()
 {
     grounded = true;
 }
 void OnTriggerExit2D()
 {
     grounded = false;
 }

I have found that approach to be unreliable, it should work but doesn’t seem to work consistently. There are many other ways to check if a character is grounded, an easy way if you are using unity built in gravity is to check it’s y velocity, if it’s not moving up or down, it should be on solid ground. So you could do bool isGrounded = rb.velocity.y < .1f && rb.velocity.y > -.1f; but there are a lot of other ways, check out this video:

there are 3 ways and if you check the comments I add in another.