I need to block the input of letters and symbols where the numbers and numbers and symbols where the characters
Example:
- Max income but I do not want to receive numbers or any symbol.
- I enter 0987563421 as a phone but I don't want to receive letters or symbols.
This is my code:
#include <iostream>
using namespace std;
int main ()
{
char n[21], a[21], c[13], tel[13], us[21], co[21];
cout <<"\n\n\n\n\t\t\t\t Tricell S.A." << endl;
cout <<"\t\t\t\t <---------------->" << endl;
cout <<"\n\t\t\t\t > Ingrese sus nombres: ";
cin.ignore(1,'\n');
cin.get(n, 21);
cout <<"\n\t\t\t\t > Ingrese sus apellidos: ";
cin.ignore(1,'\n');
cin.get(a, 21);
cout <<"\n\t\t\t\t > Ingrese su cedula: ";
cin.ignore(1,'\n');
cin.get(c, 13);
cout <<"\n\t\t\t\t > Ingrese su telefono: ";
cin.ignore(1,'\n');
cin.get(tel, 13);
cout <<"\n\t\t\t\t > Ingrese un usuario: ";
cin.ignore(1,'\n');
cin.get(us, 21);
cout <<"\n\t\t\t\t > Ingrese una contrase"<<char(164)<<"a: ";
cin.ignore(1,'\n');
cin.get(co, 21);
cout <<"\n\t\t\t\t < Datos registrados correctamente\n\n";
cin.get();
cin.get();
return 0;
}
Do you know any function or library to block characters?
Note that phone numbers can contain non-numeric characters, such as the symbol
+
:+34654321012
is equivalent to0034654321012
. On the other hand, in the names of people you can find numbers or other characters, such as the journalist Jennifer 8. Lee or the Swedish Brfxxccxxmnpcccclllmmnprxvclmnckssqlbb11116 .If you want to ignore certain values from the standard reading you can useYou could filter the values you are interested in (and ignore the rest) by discriminating between numbers and letters:ignore
, so to ignore numbers when entering lettersWith
isalpha
you can determine if a character is alphabetic or numeric.You can see the code working [here] .
For those who have the same problem or want a solution, this was the one I found and tried:
Two functions are created:
1.-
void editable (char *p);
what will be the function that will block the keyboard characters2.-
char getch ();
what will be the function that will capture a character without printing it in the c++ standard does not exist conio.h so you have to create the function