Likes

Java Lab_8_Ans_1

Write a program that the URL of the Web portal from the user, such as http://www.xyx.com,or ftp://xyz.com,and validate the format of the URL with the following fields:
- Protocol, such as https or http
-Domin, such as google or yahoo
-Top level domain, such as.co or .com

SOLUTION



import java . util . Scanner;
import java . util . regex . Matcher;
import java . util . regex . Pattern;

class UrlChecker {

 public static void main (String [] args) {
   pattern Mypattern = Pattern . compile ("^ ( (https ? |
 ftp) : // | (www | ftp) \\ .) [ a-zO-9-] + [a-z] + ) + ( [/ ?] . *) ?$" );
      Scanner input = new Scanner (System . in);
      System.out.println ("Enter the Url  to be checked:
  ");
      String name = input . nextLine ();
      Matcher Mymatcher = Mypattern . matcher (name);
      Boolen Myboolen = Mymatcher . matches ();
      if (Myboolen == true) {
          System.out.println ("Url is correct");
       } else {
          System.out.println ("Url is incorrect");
     }
  }

}

No comments: