I need to check user input from an EditText against the pattern described before inserting it into my database. If it doesnt matchI want to pop up an error message for the user. Is there an easier way of doing this than this:
public boolean myCheckMethod()
{
String s = myEditText.getText.toString();
if(s.length!=8)
return false;
for(int i=0; i < 8; i++){
if(i < 3)
if(!(Character.isLetter(s.charAt(i)) && Character.isUpperCase(s.charAt(i)))
return false;
if(i > 3)
if(!Character.isDigit(s.charAt(i)))
return false;
}
return true;
}
There HAS to be a better way of doing this!!
There is:
Then use that method in an if statement when you add to your database: