The user have to type in its IP-Adress via HTML-INPUT Field.
My Software has to check, whether the User (Client) has typed in the Adress in a correctly form, like this 192.168.11.4 <-- so it must be all numeric, 3 dots must be their.
How can I do this ?
I have found a code, but this is not indeed, a numeric check.:
String str = "192.168.2.1"; // <-- this is an example to spellcheckString
// String str = "h192.168.2.1"; // <-- this for example, could be a wrongfully spelled address
String strs[5];
int StringCount = 0;
void setup (void)
{
Serial.begin (115200);
delay(200);
while (str.length() > 0)
{
int index = str.indexOf('.');
if (index == -1) // No Dot found
{
strs[StringCount++] = str;
break;
}
else
{
strs[StringCount++] = str.substring(0, index);
str = str.substring(index+1);
}
}
for (int i = 0; i < StringCount; i++)
{
long myInt = strs[i].toInt();
// I have tried this for a spellcheck
// but if you put for example a small 'h', than a Zero comes out of the integer
// But Zeros are also used as an IP Adress
if(myInt < 1000)
{
Serial.println(myInt);
}
}
}
void loop () {}
invalid conversion from 'char*' to 'int' [-fpermissive]
char * myChar = "65465";
void setup() {
}
void loop() {
if (isDigit(myChar)) { // tests if myChar is a digit
Serial.println("The character is a number");
}
else {
Serial.println("The character is not a number");
}
}