URL validation Without protocol
java, url
Solution
check if that works for you:
boolean foundMatch = false;
try {
Pattern regex = Pattern.compile("\\b(?:(https?|ftp|file)://|www\\.)?[-A-Z0-9+&#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]\\.[-A-Z0-9+&@#/%?=~_|$!:,.;]*[A-Z0-9+&@#/%=~_|$]", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
Matcher regexMatcher = regex.matcher(subjectString);
foundMatch = regexMatcher.matches();
} catch (PatternSyntaxException ex) {
// Syntax error in the regular expression
}
Problem
I Have used URLValidator class in java to validate URL . But I Want that if user won't give any protocol in URL then also the validation should be returned as valid. Explaned Correctly: If this is supplied in URL "http://www.google.com" then also it should be a valid URL and if "www.google.com" is supplied then also the validation should returned as valid URL. I have tried a lot .Please Help me in this. Thanks In Advance.