limit keypad input digit

Hello,
I am new to programming and new to the Arduino community and was hoping one of you could provide some guidance. Basically I am trying to limit two input from keypad. I figured out how to set up the keypad and can correctly display the button I pressed. I am struggling to limit 2-digit number value eg 50. Any advice would be greatly appreciated!

void checknumber(int x){
  if (firstnumber == 99) { // Check if this is the first number entered
   firstnumber=x;
   String displayvalue = String(firstnumber);  //  Transform int to a string for display
   lcd.setCursor(10,0);
   lcd.print(displayvalue); // Redraw screen
   
  } else {
    if (secondnumber == 99) {  // Check if it's the second number entered
      secondnumber=x;
      String displayvalue = (String(firstnumber) + String(secondnumber));
     
     lcd.setCursor(10,0);
     lcd.print(displayvalue);
     lcd.print(" " );
     } 
     }
     }

You need to post the code you have written so far. It will give more context to the question you are asking.

It is not clear what you mean by limiting two-digit numbers. Do you want to limit the input to two digits, or limit the value of the number?

on a keypad, isn’t there usually an “enter” key that indicates when a complete number has been entered? what about 5 vs 50 or 100?

(deleted)

Take a look at Keypad data entry it may provide you with some ideas but it is not clear what problem you are having

I mean limitimg the value of the input number.

I posted the code.I mean limiting input number value.

Did you look at the link I posted above ?

If you get the number as an integer rather than some Frankenstein's monster collection of individual String digits then it is easy to test its value and react accordingly if it is out of range

Is ‘firstnumber’ one of the digits of the number and ‘secondnumber’ another digit?
If so this is completely the wrong way to go about entering a number.

Otherwise your posted code tells us nothing because you’ve decided to subscribe to snippets-r-us.

#include <stdio.h>
#include <string.h>

void setup() {
  Serial.begin(9600);
}

void loop() {
  int x;
  if (receivedATwoDigitNumber(x)) Serial.print(x);
}

bool receivedATwoDigitNumber(int *x) {
  static byte charsRead = 0;
  static char serialBuffer[3] = {'\0', '\0', '\0'};
  static unsigned long serialInTimestamp;
  if (serialBuffer[0] > '\0') {
    if (millis() - serialInTimestamp >= 100UL) {
      memset(serialBuffer, '\0', sizeof(serialBuffer));
      charsRead = 0;
    }
  }
  if (Serial.available()) {
    int c = Serial.read();
    if (charsRead == 0) {
      if (c >= '0' && c <= '9') {
        serialInTimestamp = millis();
        serialBuffer[0] = c;
        charsRead++;
      }
      else {
        memset(serialBuffer, '\0', sizeof(serialBuffer));
        charsRead = 0;
      }
    }
    else if (charsRead == 1) {
      if ( c >= '0' && c <= '9') {
        serialBuffer[1] = c;
        serialBuffer[2] = '\0';
        x = atoi(serialBuffer);
        memset(serialBuffer, '\0', sizeof(serialBuffer));
        charsRead = 0;
        return true;
      }
      else {
        memset(serialBuffer, '\0', sizeof(serialBuffer));
        charsRead = 0;
      }
    }
    else {
      memset(serialBuffer, '\0', sizeof(serialBuffer));
      charsRead = 0;
    }
  }
  return false;
}

Hello guys!
so I'm new to coding and was wondering if I could get some help.how can I limit two digit values for keypad coding? for example 1-50.

    if (1 > val)
         val = 1;
    if (50 < val)
         val = 50;

Can u code for a full example? I am just a newbie.

Have you thought about what you want your sketch to do if someone tries to enter an invalid value?

Having another suck of the sav are you?
Previous thread

Duplicate topics and their replies merged

Why did you start a second one ?

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a timeout from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.