This discussion is archived
3 Replies Latest reply: Sep 30, 2008 5:02 AM by 807589 RSS

Validation logic for US-ASCII characters

807589 Newbie
Currently Being Moderated
Hi folks!

I hope this question would be acceptable for all great forum members.

I just would like to know if there is a better way to validate the code point range for US-ASCII character set or
my validation logic is wrong for some reason.
Please take a look at the following validation method sample code.

By using this validation method,
I'd like a user passing a value of any other character set to be rejected for further execution.

My idea is the code point range for the US-ASCII character set is from 0 to 127.
So each character value of each String value is compared to
the maximum code point for the US-ASCII character set.
  private void validateEachElementValueHasOnlyUSASCIIChars(
      String[] aFieldValuesArray) {

    for(String fieldValue:aFieldValuesArray){
      char[] charArray = fieldValue.toCharArray();

      for(char c:charArray){
        if(c > 0x007F){// US-ASCII character set's maximum code point.
          throw new IllegalArgumentException(
              "the value you passed" +
              "("+Arrays.toString(charArray)+") contains a " +
              "character of the invalid character set.");


Similar topic: []

Thanks for your time.


Edited by: kenjiro on Sep 26, 2008 5:49 AM