Java has many builtin libraries that help developers in developing amazing apps. String matches function is used to validate the email address. In a string we define the sequence of email address and then pass this string as a argument to string matches function.
Source Code
import java.util.Scanner; public class Email{ public static void main(String[] args) { Scanner input = new Scanner (System.in); String email_validation = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$"; String email = ""; System.out.println(" Enter Email Address "); email= input.nextLine(); if (email.matches(email_validation)) { System.out.println(" Validate Email"); } else { System.out.println(" Not Validate Email "); } } }
0 comments:
Post a Comment