List of usage examples for android.util Patterns IP_ADDRESS
Pattern IP_ADDRESS
To view the source code for android.util Patterns IP_ADDRESS.
Click Source Link
From source file:Main.java
/** * Check whether an IP address is correct using Patterns.IP_ADDRESS. Does * *not* accept port numbers.//from w w w. j a v a 2 s.c o m * * @param ip to check * @return true if the given IP is correct */ public static boolean isCorrectIPAddress(String ip) { return Patterns.IP_ADDRESS.matcher(ip).matches(); }
From source file:Main.java
/** * Validate an URL with pattern//from www .j ava 2 s . c om * http://developer.android.com/reference/android/util/Patterns.html#WEB_URL * or #IP_ADDRESS * * @param url The URL to validate * @return true if the URL matches the pattern, false otherwise */ public static boolean isUrlValid(String url) { return (url == null) ? false : (Patterns.WEB_URL.matcher(url).matches() || Patterns.IP_ADDRESS.matcher(url).matches()); }
From source file:com.wly.net.PortScannerActivity.java
private boolean validateIp(final String ip) { boolean result = Patterns.IP_ADDRESS.matcher(ip).matches(); Log.i(TAG, " Validation of " + ip + " returned " + String.valueOf(result)); return result; }
From source file:com.oinux.lanmitm.util.RequestParser.java
public static String getBaseDomain(String hostname) { String domain = ""; // if hostname is an IP address return that address if (Patterns.IP_ADDRESS.matcher(hostname).matches()) return hostname; for (String tld : TLD) { if (hostname.endsWith(tld)) { String[] host_parts = hostname.split("\\."), tld_parts = tld.split("\\."); int itld = tld_parts.length, ihost = host_parts.length, i = 0, stop = ihost - 1; domain = ""; for (i = ihost - itld; i <= stop; i++) { domain += host_parts[i] + (i == stop ? "" : "."); }//from w ww . ja v a 2s . c o m return domain; } } int startIndex = 0, nextIndex = hostname.indexOf('.'), lastIndex = hostname.lastIndexOf('.'); while (nextIndex < lastIndex) { startIndex = nextIndex + 1; nextIndex = hostname.indexOf('.', startIndex); } if (startIndex > 0) return hostname.substring(startIndex); else return hostname; }
From source file:org.rm3l.ddwrt.mgmt.AbstractRouterMgmtDialogFragment.java
private boolean validateForm(@NotNull AlertDialog d) { @NotNull//from w ww.j a v a2s . co m final EditText ipAddrView = (EditText) d.findViewById(R.id.router_add_ip); final Editable ipAddrViewText = ipAddrView.getText(); if (!(Patterns.IP_ADDRESS.matcher(ipAddrViewText).matches() || Patterns.DOMAIN_NAME.matcher(ipAddrViewText).matches())) { displayMessage(getString(R.string.router_add_dns_or_ip_invalid) + ":" + ipAddrViewText, ALERT); ipAddrView.requestFocus(); openKeyboard(ipAddrView); return false; } boolean validPort; @NotNull final EditText portView = (EditText) d.findViewById(R.id.router_add_port); try { final String portStr = portView.getText().toString(); validPort = (!isNullOrEmpty(portStr) && (Integer.parseInt(portStr) > 0)); } catch (@NotNull final Exception e) { e.printStackTrace(); validPort = false; } if (!validPort) { displayMessage(getString(R.string.router_add_port_invalid) + ":" + portView.getText(), ALERT); portView.requestFocus(); openKeyboard(portView); return false; } @NotNull final EditText sshUsernameView = (EditText) d.findViewById(R.id.router_add_username); if (isNullOrEmpty(sshUsernameView.getText().toString())) { displayMessage(getString(R.string.router_add_username_invalid), ALERT); sshUsernameView.requestFocus(); openKeyboard(sshUsernameView); return false; } final int checkedAuthMethodRadioButtonId = ((RadioGroup) d.findViewById(R.id.router_add_ssh_auth_method)) .getCheckedRadioButtonId(); if (checkedAuthMethodRadioButtonId == R.id.router_add_ssh_auth_method_password) { //Check password @NotNull final EditText sshPasswordView = (EditText) d.findViewById(R.id.router_add_password); if (isNullOrEmpty(sshPasswordView.getText().toString())) { displayMessage(getString(R.string.router_add_password_invalid), ALERT); sshPasswordView.requestFocus(); openKeyboard(sshPasswordView); return false; } } else if (checkedAuthMethodRadioButtonId == R.id.router_add_ssh_auth_method_privkey) { //Check privkey @NotNull final TextView sshPrivKeyView = (TextView) d.findViewById(R.id.router_add_privkey_path); if (isNullOrEmpty(sshPrivKeyView.getText().toString())) { displayMessage(getString(R.string.router_add_privkey_invalid), ALERT); sshPrivKeyView.requestFocus(); return false; } } return true; }