List of usage examples for java.util.regex Pattern matches
public static boolean matches(String regex, CharSequence input)
From source file:com.oncore.calorders.core.utils.FormatHelper.java
/** * Checks if the CharSequence is a valid email address format * * <pre>// w w w .j a v a2s .c o m * PageUtilities.isValidEmailAddress(null) = false * PageUtilities.isValidEmailAddress("") = false * PageUtilities.isValidEmailAddress(" ") = false * PageUtilities.isValidEmailAddress("abc") = false * PageUtilities.isValidEmailAddress("ab@") = false * PageUtilities.isValidEmailAddress("ab@c") = false * PageUtilities.isValidEmailAddress("ab@xyz.com") = true * </pre> * * @author OnCore Consulting LLC * * @param address an email address to validate * * * @return true if the value is a valid address, false otherwise */ public static Boolean isValidEmailAddress(final String address) { Boolean result = Boolean.FALSE; if (StringUtils.isNotBlank(address)) { try { result = Pattern.matches("[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\\.[a-zA-Z]{2,4}", address); } catch (PatternSyntaxException px) { Logger.warn(LOG, "Invalid email pattern detected"); } catch (Exception ex) { Logger.warn(LOG, "Fatal error occurred during email validation check"); } } return result; }
From source file:com.gote.downloader.kgs.KGSDownloader.java
/** * From KGS result, tells the game result * /*from w w w .j a v a 2 s . c om*/ * @param pKGSResult String as "W+0.5" * @return TournamentOpenGothaUtil Result value */ public String getStdResultFromKGSResult(String pKGSResult) { if (Pattern.matches("(w|W)[\\w\\p{Punct}\\s]*", pKGSResult)) { return TournamentOpenGothaUtil.VALUE_GAME_RESULT_WHITEWINS; } else if (Pattern.matches("(b|B)[\\w\\p{Punct}\\s]*", pKGSResult)) { return TournamentOpenGothaUtil.VALUE_GAME_RESULT_BLACKWINS; } return TournamentOpenGothaUtil.VALUE_GAME_RESULT_UNKNOWN; }
From source file:com.jsfsample.util.StringUtil.java
/** * Check if a string is a valid driver license * // www. j a v a 2 s . c o m * @param string * -- 15 long licnese characters * @param aDate * -- dob of driver * @return boolean */ public static boolean isValidDriverLicense(Date aDate, String str) { boolean valid = false; valid = Pattern.matches("[a-zA-Z]\\d{12}(0[1-9]|[12][0-9]|3[01])", str); if (valid) { String strDate = DateUtil.getDate(aDate); String str1011 = str.substring(9, 11); // 10th and 11th characters // -- year of driver's dob String str1415 = str.substring(13, 15);// 14th and 15th characters // -- day of driver's dob String dobdd = strDate.substring(3, 5); String dobyy = strDate.substring(8, 10); if (!dobdd.equals(str1415) || !dobyy.equals(str1011)) { valid = false; } } return valid; }
From source file:com.ittm_solutions.ipacore.IpaApi.java
/** * Checks the string (a part of the content) for known errors. * <p>//from w w w .j a va 2s . c o m * This method reads through the given substring of the response content and * checks whether it contains a fragment that could indicate an error. * * @return null or the error indicator */ private static IpaErrorIndication containsStringIndicatingError(String contentFragement) { // FIXME an error div may span multiple lines, and could include other // divs; these regexes are not sufficient, a real xml parser should be // used final Pattern errDivRgx1 = Pattern.compile(".*?<\\s*div\\s+id='errors'.*?>(.*?)</\\s*div\\s*>.*"); final Pattern errDivRgx2 = Pattern.compile(".*?<\\s*div\\s+id='errors'.*?>(.*)"); if (Pattern.matches(".*Your current IPA license does not have privileges to access this feature.*", contentFragement)) { return IpaErrorIndication.UNAUTHORIZED; } if (Pattern.matches( ".*The dataset name \\(.*?\\) already exists in the project .*?\\.\\s+Please choose a different dataset name.*", contentFragement)) { return IpaErrorIndication.DATASET_NAME_EXISTS; } if (Pattern.matches( ".*The analysis name \\(.*?\\) already exists in the project .*?\\.\\s+Please choose a different analysis name.*", contentFragement)) { return IpaErrorIndication.ANALYSIS_NAME_EXISTS; } if (Pattern.matches("^No analysis found for ID=(\\d+) for userId=(\\d+)$", contentFragement)) { return IpaErrorIndication.ANALYSIS_ID_NOT_FOUND; } if (Pattern.matches(".*session has been expired.*", contentFragement)) { return IpaErrorIndication.SESSION_EXPIRED; } Matcher m1 = errDivRgx1.matcher(contentFragement); if (m1.find()) { IpaErrorIndication err = IpaErrorIndication.OTHER; err.setMessage(m1.group(1)); return err; } Matcher m2 = errDivRgx2.matcher(contentFragement); if (m2.find()) { IpaErrorIndication err = IpaErrorIndication.OTHER; err.setMessage(m2.group(1)); return err; } if (Pattern.matches("<\\s*html.*", contentFragement)) { return IpaErrorIndication.CONTAINS_HTML; } return null; }
From source file:dhbw.ka.mwi.businesshorizon2.ui.login.LogInScreenPresenter.java
/** * Prueft ob es sich um eine gltige Mailadresse handelt und gibt "true" * fuer gltig und "false" fuer nicht gltig zurueck. Eine Mailadresse muss * aus mindestens einem Zeichen vor dem '@', mindestens einem zwischen '@' * und Domain, einem Punkt und einer Domain bestehen. Bei keiner * Uebereinstimmung wird zudem eine Fehlermeldung an die ViewImpl zur * Ausgabe zurueckgegeben.//from w w w. ja v a2 s . c o m * * @author Marcel Rosenberger, Annika Weis * @return Ob es sich um eine gltige Mailadresse handelt. */ private boolean validateMailAdress() { boolean validMailAdress; // hier wird die Mailadresse berprft if (Pattern.matches( "^([a-zA-Z0-9]+(?:[._+-][a-zA-Z0-9]+)*)@([a-zA-Z0-9]+(?:[.-][a-zA-Z0-9]+)*[.][a-zA-Z]{2,})$", emailAdress)) { validMailAdress = true; logger.debug("Mailadresse gltig."); } else { validMailAdress = false; getView().showErrorMessage("Bitte geben Sie eine gltige Mailadresse ein."); logger.debug("Mailadresse ungltig."); } return validMailAdress; }
From source file:net.spfbl.whois.Domain.java
/** * Verifica se o endereo contm um domnio. * @param address o endereo a ser verificado. * @return verdadeiro se o endereo contm um domnio. *///from ww w . j a v a2 s . co m public static boolean isHostname(String address) { if (address == null) { return false; } else { address = address.trim(); if (SubnetIPv4.isValidIPv4(address)) { return false; } else { address = address.toLowerCase(); return Pattern.matches( "^\\.?" + "(([a-zA-Z0-9_]|[a-zA-Z0-9_][a-zA-Z0-9_-]{0,61}[a-zA-Z0-9_])" + "(\\.([a-zA-Z0-9_]|[a-zA-Z0-9_][a-zA-Z0-9_-]{0,61}[a-zA-Z0-9]))*)" + "\\.?$", address); } } }
From source file:com.b2international.snowowl.snomed.importer.net4j.SnomedSubsetImportUtil.java
private boolean isConceptId(final String sctId) { if (!Pattern.matches("^\\d*$", sctId) || sctId.length() < 6 || sctId.length() > 18) { return false; }//from w w w . java2 s . c om if (!VerhoeffCheck.validateLastChecksumDigit(sctId)) { return false; } final String componentNatureId = sctId.substring(sctId.length() - 2, sctId.length() - 1); if ("1".equals(componentNatureId)) { return false; } if ("2".equals(componentNatureId)) { return false; } return true; }
From source file:ambroafb.general.AnnotiationUtils.java
private static boolean checkValidationForContentAmountAnnotation(Field field, Object currSceneController) { boolean contentIsCorrect = false; Annotations.ContentAmount annotation = field.getAnnotation(Annotations.ContentAmount.class); Object[] typeAndContent = getNodesTypeAndContent(field, currSceneController); String integerPartPattern = annotation.valueForIntegerPart(); int outerIntegerPartMaxLen = annotation.integerPartMaxLen(); if (outerIntegerPartMaxLen > 0) { integerPartPattern = annotation.valueForIntegerPart().replaceFirst( "" + (Annotations.ContentAmount.integerPartMaxLen - 1), "" + annotation.integerPartMaxLen()); }//from w w w . ja v a 2 s .co m if (!Pattern.matches(integerPartPattern, (String) typeAndContent[1])) { String integerPartExplain = (outerIntegerPartMaxLen > 0) ? "" + outerIntegerPartMaxLen : "" + Annotations.ContentAmount.integerPartMaxLen; String explainFromBundle = GeneralConfig.getInstance().getTitleFor(annotation.explainForIntegerPart()); String integerPartExp = explainFromBundle.replaceFirst("#", integerPartExplain); changeNodeTitleLabelVisual((Node) typeAndContent[0], integerPartExp); } else if (!Pattern.matches(annotation.valueForFractionalPart(), (String) typeAndContent[1])) { String explainFromBundle = GeneralConfig.getInstance() .getTitleFor(annotation.explainForFractionalPart()); String fractionalPartExp = explainFromBundle.replaceFirst("#", "" + Annotations.ContentAmount.fractionalPartMaxLen); changeNodeTitleLabelVisual((Node) typeAndContent[0], fractionalPartExp); } else if (!Pattern.matches(annotation.valueForWhole(), (String) typeAndContent[1])) { changeNodeTitleLabelVisual((Node) typeAndContent[0], annotation.explainForWhole()); } else { changeNodeTitleLabelVisual((Node) typeAndContent[0], ""); contentIsCorrect = true; } return contentIsCorrect; }
From source file:com.thoughtworks.go.server.service.MagicalMaterialAndMaterialConfigConversionTest.java
private boolean isNotAConcrete_NonTest_MaterialConfigImplementation(Class aClass) { return Pattern.matches(".*(Test|Dummy).*", aClass.toString()) || Modifier.isAbstract(aClass.getModifiers()); }
From source file:com.jaspersoft.jasperserver.remote.services.impl.ResourcesManagementRemoteServiceImpl.java
/** * Generic entry point to create a new resource. * * @param resourceDescriptor/*w w w.ja va 2s. c o m*/ */ public ResourceDescriptor putResource(ResourceDescriptor resourceDescriptor) throws ServiceException { final String uriString = resourceDescriptor.getUriString(); if (Pattern.matches(".*/" + TenantService.ORGANIZATIONS + "/[^/]+$", uriString)) { // 'organizations' is technical folder. No resources is permitted to be created here throw new ServiceException(ServiceException.FORBIDDEN, "Creation of resources in " + TenantService.ORGANIZATIONS + " folder isn't allowed"); } if (!ResourceDescriptor.TYPE_FOLDER.equals(resourceDescriptor.getWsType()) && Pattern.matches("/[^/]+$|.*/" + TenantService.ORGANIZATIONS + "(/[^/]+){2}$", uriString)) { // only folders can be created in root folder or organization's root folder throw new ServiceException(ServiceException.FORBIDDEN, "Creation of resources in root folder isn't allowed"); } try { ResourceHandler handler = getHandler(resourceDescriptor.getWsType()); if (handler == null) { throw new ServiceException(ServiceException.RESOURCE_BAD_REQUEST, "The resource type is not supported by this server"); } return handler.update(resourceDescriptor, null, true); } catch (ServiceException se) { throw se; } catch (AccessDeniedException ex) { // Let's try to be as specific as possible with the errors... throw new ServiceException(ServiceException.FORBIDDEN, ex.getLocalizedMessage()); } }