ফাঁকা ইনপুট −
সহ প্রদত্ত ই-মেইল আইডির সাথে নিয়মিত অভিব্যক্তির মিল অনুসরণ করুন^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6})?$ কোথায়,
-
^ বাক্যটির শুরুর সাথে মিলে যায়।
-
[a-zA-Z0-9._%+-] @ চিহ্নের আগে ইংরেজি বর্ণমালা (উভয় ক্ষেত্রেই), অঙ্ক, "+", "_", "."," এবং "-" থেকে একটি অক্ষর মেলে .
-
+ উপরে উল্লিখিত অক্ষরগুলির এক বা একাধিক বার পুনরাবৃত্তি নির্দেশ করে৷
-
@ নিজেই মেলে
-
[a-zA-Z0-9.-] ইংরেজি বর্ণমালা থেকে একটি অক্ষর মেলে (উভয় ক্ষেত্রেই), অঙ্ক, "।" এবং @ চিহ্নের পরে "-"
-
\[a-zA-Z]{2,6} ইমেল ডোমেনের জন্য দুই থেকে 6 অক্ষর "।"
-
$ বাক্যটির শেষ নির্দেশ করে
উদাহরণ 1
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SampleTest {
public static void main( String args[] ) {
String regex = "^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6})?$";
//Reading input from user
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name: ");
String name = sc.nextLine();
System.out.println("Enter your e-mail: ");
String e_mail = sc.nextLine();
System.out.println("Enter your age: ");
int age = sc.nextInt();
//Instantiating the Pattern class
Pattern pattern = Pattern.compile(regex);
//Instantiating the Matcher class
Matcher matcher = pattern.matcher(e_mail);
//verifying whether a match occurred
if(matcher.find()) {
System.out.println("e-mail value accepted");
} else {
System.out.println("e-mail not value accepted");
}
}
} আউটপুট1
Enter your name: krishna Enter your e-mail: Enter your age: 20 e-mail value accepted
আউটপুট 2
Enter your name: Rajeev Enter your e-mail: rajeev.123@gmail.com Enter your age: 25 e-mail value accepted
উদাহরণ 2
import java.util.Scanner;
public class Example {
public static void main(String args[]) {
//Reading String from user
System.out.println("Enter email address: ");
Scanner sc = new Scanner(System.in);
String e_mail = sc.nextLine();
//Regular expression
String regex = "^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6})?$";
boolean result = e_mail.matches(regex);
if(result) {
System.out.println("Valid match");
} else {
System.out.println("Invalid match");
}
}
} আউটপুট 1
Enter email address: rajeev.123@gmail.com Valid match
আউটপুট 2
Enter email address: Valid match