validation - How to validate url in java? -
i have 1 inputtext have come in link . how going validate string url(link) or not. example-
pattern p = pattern .compile("(@)?(href=')?(href=')?(href=\")?(href=\")?(http://)?[a-za-z_0-9\\-]+(\\.\\w[a-za-z_0-9\\-]+)+(/[#&\\n\\-=?\\+\\%/\\.\\w]+)?"); matcher m = p.matcher("https://mail.google.com"); system.out.println(m.matches()); this code gives false.i not getting problem in code. or please refer logic validate url. had used urlvalidator urlvalidator = new urlvalidator(); dont want utilize .jar
this method method validate url not available.how check requirement? example-
public static void main(string[] args) { string b = "http://11155555.com/"; system.out.println(isurl(b)); } public static boolean isurl(string str) { pattern urlpattern = pattern.compile( "((https?|ftp|gopher|telnet|file):((//)|(\\\\\\\\))+[\\\\w\\\\d:#@%/;$()~_?\\\\+-=\\\\\\\\\\\\.&]*)", pattern.case_insensitive); matcher matcher = urlpattern.matcher(str); if (matcher.find()) { homecoming true; } else { homecoming false; } } thanks in advanced.
try 1 :
public static boolean isurl(string str){ pattern urlpattern = pattern.compile("((https?|ftp|gopher|telnet|file):((//)|(\\\\\\\\))+[\\\\w\\\\d:#@%/;$()~_?\\\\+-=\\\\\\\\\\\\.&]*)",pattern.case_insensitive); matcher matcher = urlpattern.matcher(str); if (matcher.find()) homecoming true; else homecoming false; } java validation jsf-2
No comments:
Post a Comment