1 19 20 package com.sslexplorer.input.validators; 21 22 import java.util.regex.Pattern ; 23 24 30 public class HostnameOrIPAddressValidator extends StringValidator { 31 32 private static final int MAX_HOST_OR_IP_CHARS = 255; 33 37 final static String HOST_PATTERN = "^[a-zA-Z0-9\\.\\-\\_]*"; 38 39 42 public HostnameOrIPAddressValidator() { 43 super(1, MAX_HOST_OR_IP_CHARS, HOST_PATTERN, null, true); 44 this.regExpErrCode = ErrorConstants.ERR_STRING_ISNT_HOSTNAME_OR_IPADDRESS; 45 } 46 47 53 public static boolean isValidAsHostOrIp(String value){ 54 if (value.length() > MAX_HOST_OR_IP_CHARS) 55 return false; 56 else 57 return Pattern.compile(HOST_PATTERN).matcher(value).matches(); 58 } 59 60 } 61 | Popular Tags |