Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to apply validation on aiphanumeric series starting with 4 characters with 4 letters in java

// Java program to check string is
// alphanumeric or not using Regular Expression.
 
import java.util.regex.*;
 
class GFG {
 
    // Function to check string is alphanumeric or not
    public static boolean isAlphaNumeric(String str)
    {
        // Regex to check string is alphanumeric or not.
        String regex = "^(?=.*[a-zA-Z])(?=.*[0-9])[A-Za-z0-9]+$";
 
        // Compile the ReGex
        Pattern p = Pattern.compile(regex);
 
        // If the string is empty
        // return false
        if (str == null) {
            return false;
        }
 
        // Pattern class contains matcher() method
        // to find matching between given string
        // and regular expression.
        Matcher m = p.matcher(str);
 
        // Return if the string
        // matched the ReGex
        return m.matches();
    }
 
    // Driver Code.
    public static void main(String args[])
    {
 
        // Test Case 1:
        String str1 = "GeeksforGeeks123";
        System.out.println(
            str1 + ": "
            + isAlphaNumeric(str1));
 
        // Test Case 2:
        String str2 = "GeeksforGeeks";
        System.out.println(
            str2 + ": "
            + isAlphaNumeric(str2));
 
        // Test Case 3:
        String str3 = "GeeksforGeeks123@#";
        System.out.println(
            str3 + ": "
            + isAlphaNumeric(str3));
 
        // Test Case 4:
        String str4 = "123";
        System.out.println(
            str4 + ": "
            + isAlphaNumeric(str4));
 
        // Test Case 5:
        String str5 = "@#";
        System.out.println(
            str5 + ": "
            + isAlphaNumeric(str5));
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: factorial java recursion 
Java :: compare array with himself java 
Java :: java clump list 
Java :: compile option in android 
Java :: create a file in java in user home 
Java :: add elements to arraylist of arraylist in java 
Java :: run app by package android 
Java :: how to iterate list in java selenium 
Java :: convert code python to java 
Java :: Original authors: Talmon Marco, Igor Magazinnik Programming languages: Java, C, Python, C , Qt, Objective-C 
Java :: java resultset.absolute 
Java :: download a website as string kotlin 
Java :: collapsingtoolbarlayout collapse listener 
Java :: how many return values can a method hava java 
Java :: Write a java program to merge three singly linked list elements 
Java :: TestNG Data Provider 
Java :: public class Hello { public static void main( String[] args ){ System.out.println("Hello World"); } } 
Java :: how to implement count steps in android 
Java :: sudoku generator java code 
Java :: last element array java 
Java :: Why String is popular HashMap key in Java? 
Java :: java switch case enum 
Java :: JAVA for-each Loop Sytnax 
Java :: @Controller 
Java :: java operator 
Java :: find minimum of array java 
Java :: java schleifendurchläufe zählen 
Java :: JSP Convertir Int a String 
Java :: java add xmlns attribute 
Java :: Automatic Code Completion in NetBeans 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =