devxlogo

Regex Has a Presence in Java as Well

Regex Has a Presence in Java as Well

See how to use this form of Regex below to identify whether or not a string has only alphabets present.

public class RegexHasOnlyAlphabets{      public static void main(String args[]) {      RegexHasOnlyAlphabets regexHasOnlyAlphabets = new RegexHasOnlyAlphabets();      regexHasOnlyAlphabets.proceed();   }   public void proceed()    {      String inputStr = "HasOnlyAplhabets";      System.out.println("Has only alphabets: " + inputStr + ": " + checkIfInputHasOnlyAlphabets(inputStr));      inputStr = "HasOnly3Aplhabets";      System.out.println("Has only alphabets: " + inputStr + ": " + checkIfInputHasOnlyAlphabets(inputStr));   }            public boolean checkIfInputHasOnlyAlphabets(String strArg)    {      return          (            (null != strArg) &&          (! strArg.equals("")) &&         (strArg.matches("^[a-zA-Z]*$"))         );    }       }/*

Expected output:

[root@mypc]# java RegexHasOnlyAlphabetsHas only alphabets: HasOnlyAplhabets: trueHas only alphabets: HasOnly3Aplhabets: false*/
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist