... just so long as you already know what the answer will be. Well that, and that the answer is "Yes." Otherwise, you'll get yourself caught up in some trouble. Some Execptional trouble. Jacob Robertson found that out the hard way when he used the isAlphaNumeric() method from their framework library to validate user input. But now he does the right thing; he makes sure things are valid before trying to validate them ...

public class FieldFormat {

 

  private boolean isAlphaNumeric;

 

  // snip

  public FieldFormat(boolean isAlphaNumeric) {

    this.isAlphaNumeric = isAlphaNumeric;

  }

 

  // snip

  public boolean isAlphaNumericOnly(String value) {

    char[] character = value.toCharArray();

    for (int i = 0; i < character.length; i++) {

      isAlphaNumeric = (Character.isLetter(character[i])

                       || Character.isDigit(character[i])

                       || Character.isSpaceChar(character[i])

                       || character[i] == '.' 
                       || character[i] ==
'#'
                       || character[i] ==
'-');

      if (!isAlphaNumeric) {

         throw new IllegalArgumentException("only alpha numeric");

       }

     }

     return this.isAlphaNumeric;

  }

}

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!