What's new

Closed error trapping of user inputs. para sa makulit na user

Status
Not open for further replies.

thereal00

Honorary Poster
Joined
Jun 20, 2018
Posts
452
Reaction
69
Points
158
help naman po mga master ng c# jan.
ano pong method ang ginagawa nyo para ma trap yung error dahil sa maling input ng user. for examples hiningian ko ng intergers si user then alphabet ang ininput nya. tendency is nagloloko si program. ang ginagawa ko lang kasi is string lagi ang variable ko para kahit anong input ni user idi display kahit alphanumeric. pero gusto ko sana mag improve. for example hiningian ko ng "name " si user tapos ang input nya is puro numbers. ano pong ginagawa nyo para mag display sya ng for example "pls input a name!"

sana may makatulong. self study lang ako sa c# mga sir. gusto ko lang mag improve. salamat
 
theres a lot of ways to do it. use the keypress event(VS), or use parsing functions. In EF you can also use data annotations or fluent api.
 
theres a lot of ways to do it. use the keypress event(VS), or use parsing functions. In EF you can also use data annotations or fluent api.

ty idol. naitest ko na sir tryparse mukang yun nga sagot sa hinahanap ko. pero pano kung string yung input? walang parse si string diba? di ko maintindihan masyado yung mga tutorial sa YøùTùbé eh haha puro arabo
 
regex is one of the best solution. About sa concern mo sir about sa string? e di gawa ka ng method mo for evaluating numeric inputs, so pag hindi sya numeric automatic string yun or character. You might not need another method for evaluating strings(unless you need it and for other purposes). Make sense?
 
Sa palagay ko hindi regex ang best solution dito kundi kung ano man yung input validator na inio-offer ng language mo. Unless perl ito o some scripting language.;
 
Gamit kang userdefined method na parang ganito:
Code:
public bool numberChecker(String userin)
{
    bool deter = false;

    for (int x = 0; x < userin.Length; x++)
    {
        if (userin[x] == '1' || userin[x] == '2' || userin[x] == '3' || userin[x] == '4' || userin[x] == '5' || userin[x] == '6' || userin[x] == '7' || userin[x] == '8' || userin[x] == '9' || userin[x] == '0')
        {
            deter = true;
            break;
        }
    }
    return deter;
 }
 
Eto crude validator:

C++:
  1 #include <iostream>
  2
  3 int main(void) {
  4     short unsigned myinput {0};
  5     std::cout << "Enter integer between 1-5 only: " << std::flush;
  6     std::cin >> myinput;
  7     while (myinput < 1 || myinput > 5) {
  8         std::cout << "Invalid input. Please re-enter: " << std::flush;
  9         std::cin >> myinput;
10     }  
11     std::cout << "You have successfully entered a valid value of: " << myinput << "!" << std::endl;
12     return 0;
13 }
 
Status
Not open for further replies.
Back
Top