litesoft
@ 625
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
package com.temp.shared.validators; import com.temp.shared.*; import com.temp.shared.externalization.*; import com.temp.shared.utils.*; public class AlphaNumericUnderScore7bitAsciiValueValidator implements ValueValidator { public static final String TEMPLATE_ID_CODE = "Only7bitAlphaNumericUnderScore"; public static final String TEMPLATE_NAME_WHY = "why"; public static final String SUBTEMPLATE_WHY_NOT_STRING = "NotString"; public static final String SUBTEMPLATE_WHY_EMPTY_STRING = "EmptyString"; public static final ValueValidator INSTANCE = new AlphaNumericUnderScore7bitAsciiValueValidator(); private AlphaNumericUnderScore7bitAsciiValueValidator() { } @Override public E13nData checkValue(Object value) { if (!(value instanceof String)) { return new E13nData(TEMPLATE_ID_CODE).addSubstitutionNamedSubTemplateIdCode(TEMPLATE_NAME_WHY, SUBTEMPLATE_WHY_NOT_STRING); } String userData = value.toString().trim(); if (userData.length() == 0) { return new E13nData(TEMPLATE_ID_CODE).addSubstitutionNamedSubTemplateIdCode(TEMPLATE_NAME_WHY, SUBTEMPLATE_WHY_EMPTY_STRING); } for (int i = 0; i < userData.length(); i++) { char c = userData.charAt(i); if ( !CharacterUtils.isAlphaNumericUnderScore7bitAscii(c) ) { } } return null; // OK! } } |