List of usage examples for com.liferay.portal.kernel.util StringUtil extractDigits
public static String extractDigits(String s)
From source file:com.liferay.util.CreditCard.java
License:Open Source License
public static boolean isValidNumber(String number, String type) { number = StringUtil.extractDigits(number); if (type.equals("visa")) { if (!number.startsWith("4")) { return false; }/* w w w . j ava 2s.c om*/ if ((number.length() != 13) && (number.length() != 16)) { return false; } } else if (type.equals("mastercard")) { if (!number.startsWith("51") && !number.startsWith("52") && !number.startsWith("53") && !number.startsWith("54") && !number.startsWith("55")) { return false; } if (number.length() != 16) { return false; } } else if (type.equals("discover")) { if (!number.startsWith("6011")) { return false; } if (number.length() != 16) { return false; } } else if (type.equals("amex")) { if (!number.startsWith("34") && !number.startsWith("35") && !number.startsWith("36") && !number.startsWith("37")) { return false; } if (number.length() != 15) { return false; } } return Validator.isLUHN(number); }
From source file:com.liferay.util.format.USAPhoneNumberFormat.java
License:Open Source License
public String strip(String phoneNumber) { return StringUtil.extractDigits(phoneNumber); }
From source file:com.liferay.util.InetAddressTask.java
License:Open Source License
@Override public void execute() throws BuildException { try {//from w w w . j a va 2 s. c o m InetAddress localHost = InetAddress.getLocalHost(); if (Validator.isNotNull(_hostAddressProperty)) { getProject().setUserProperty(_hostAddressProperty, localHost.getHostAddress()); } if (Validator.isNotNull(_hostNameProperty)) { getProject().setUserProperty(_hostNameProperty, localHost.getHostName()); } if (Validator.isNotNull(_vmId1Property)) { int id = GetterUtil.getInteger(StringUtil.extractDigits(localHost.getHostName())); getProject().setUserProperty(_vmId1Property, String.valueOf((id * 2) - 1)); } if (Validator.isNotNull(_vmId2Property)) { int id = GetterUtil.getInteger(StringUtil.extractDigits(localHost.getHostName())); getProject().setUserProperty(_vmId2Property, String.valueOf((id * 2))); } } catch (UnknownHostException uhe) { throw new BuildException(uhe); } }
From source file:com.liferay.util.PwdGenerator.java
License:Open Source License
private static String _getPassword(String key, int length, boolean useAllKeys) { int keysCount = 0; if (key.contains(KEY1)) { keysCount++;// w w w. java 2 s . c o m } if (key.contains(KEY2)) { keysCount++; } if (key.contains(KEY3)) { keysCount++; } if (keysCount > length) { if (_log.isWarnEnabled()) { _log.warn("Length is too short"); } length = keysCount; } StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { sb.append(key.charAt((int) (Math.random() * key.length()))); } String password = sb.toString(); if (!useAllKeys) { return password; } boolean invalidPassword = false; if (key.contains(KEY1)) { if (Validator.isNull(StringUtil.extractDigits(password))) { invalidPassword = true; } } if (key.contains(KEY2)) { if (password.equals(password.toLowerCase())) { invalidPassword = true; } } if (key.contains(KEY3)) { if (password.equals(password.toUpperCase())) { invalidPassword = true; } } if (invalidPassword) { return _getPassword(key, length, useAllKeys); } return password; }