Try to search your question here, if you can't find : Ask Any Question Now ?

A period must not appear consecutively in a String Java

HomeCategory: stackoverflowA period must not appear consecutively in a String Java
julie asked 3 weeks ago

I have a code check if the user input is valid in the regular expression pattern. The patter is @ the problem is how to check if the character . appears consecutively

[a-z|A-Z|0-9|[.]{1}]+@[[a-z|A-Z|0-9]+
i’ve tried this patter so far.

    System.out.print("Enter your Email: ");
    String userInput = new Scanner(System.in).nextLine();

    Pattern pat = Pattern.compile("[a-z|A-Z|0-9|[.]{1}]+@[a-z|A-Z|0-9]+");
    Matcher mat = pat.matcher(userInput);

    if(mat.matches()){
        System.out.print("Valid");
    }else{
        System.out.print("Invalid");
    }

}

}

if the input is een..123@asd123
I expect the output will Invalid but if the input is een.123@asd123 the output will Valid

1 Answers
Best Answer
Fernando answered 3 weeks ago
Your Answer

14 + 1 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com