Validate URL Format

This program validates URL format using regex.

Problem Statement

Write a Java program to validate URL format.

Source Code

1 public class RegexURLValidation {
2 public static void main(String[] args) {
3 System.out.println("Eduinq Regex URL Validation");
4 String url="https://www.eduinq.com";
5 String regex="^(https?|ftp)://[^\\s/$.?#].[^\\s]*$";
6 if(url.matches(regex)) System.out.println("Valid URL");
7 else System.out.println("Invalid URL");
8 }
9 }

Program Output

Eduinq Regex URL Validation
Valid URL

Explanation

Regex checks protocol and domain format. - matches() validates URL. - Together demonstrates URL validation. Conclusion: Shows how to validate URL using regex.

Quick Links to Explore