Java programme to validate Facebook url
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.mavenproject1;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author ASUS
*/
public class Helloworld {
private static String facebookurl="";
private static boolean facebook(String url){
Pattern p = Pattern.compile("^(https\\:\\/\\/)?(www\\.)?(facebook\\.com)\\/.+$");
Matcher m=p.matcher(url);
boolean matches = m.matches();
return matches;
}
public static void main(String[] args){
System.out.println("result of facebook url"+ facebook(facebookurl));
}
}
In the above programme just replace facebookurl to the url of facebook
Pattern Class in java
Example
Pattern p = Pattern.compile
("a*b"); Matcher m = p.matcher
("aaaaab"); boolean b = m.matches
();
boolean b = Pattern.matches("a*b", "aaaaab");