Hi All
how to set text field validation only numeric values?
Help me
Printable View
Hi All
how to set text field validation only numeric values?
Help me
Try something like this,
Code:String temp = txtField.getText();
try {
int val = Integer.parseInt(temp);
}
catch(NumberFormatException e) {
System.out.println("Invalid");
}
In that sense try to make a pattern and validate. Or in simple way, validate each number separating with the dot. Since you are talking about IPs, best thing would be patterns.
Refer regex documentation.
One more way is u can trim the IP address for "." and then do a Integer.parseInt() for each part.
I don't think he want to read that a long material. ;)