Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3613262
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:06:06+00:00 2026-05-18T22:06:06+00:00

I have an edit box. I am checking if the email address entered is

  • 0

I have an edit box. I am checking if the email address entered is valid or not.

Pattern pattern1 = Pattern.compile("^[\\w-]*@[\\.\\w-]*$");
Pattern pattern2 = Pattern.compile("^\\w+$");
Matcher matcher1 = pattern1.matcher(string);
Matcher matcher2 = pattern2.matcher(string);    
return matcher1.matches();
return matcher2.matches();

Problem with this if my input my email address as spunker.baba@foo.com. matcher return false. It consider the char “.” as invalid.

How should i modify my code such that it supports “.” and matcher return true.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:06:06+00:00Added an answer on May 18, 2026 at 10:06 pm

    It’s not clear why you’ve got two patterns (and two return statements!) instead of one… but your first pattern only includes \w and - before the @ sign, although it allows . afterwards. That’s easy to modify, so that the first part is the same as the second part:

    Pattern pattern1 = Pattern.compile("^[\\.\\w-]*@[\\.\\w-]*$");
    

    However, there are plenty of sites giving rather more exact email address matching regular expression patterns – for example this one in Perl (which I suspect will port simply enough to Java). There’s also a page with a fairly long explanation and Java code, if you want to also cope with addresses including friendly names. I’m sure if you search around you’ll find a pattern which meets your exact needs – although quite how you judge which pages are reliable is another matter.

    EDIT: If you want to be able to match without the last part, you can make it optional like this:

    Pattern pattern1 = Pattern.compile("^[\\.\\w-]*(@[\\.\\w-]*)?$");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with an edit box for entering valid email-address. I dont
I need to edit XML files on a small Linux box that we have
EDIT: I have added Slug column to address performance issues on specific record selection.
I need to have my edit box work the same for both tab and
I have two modal dialogs and each dialog has one edit box. I am
in my app in have an edit box when the user types a web
I've ran into next mystic thing in Winapi/MFC, I have an edit box, contents
I have placed an edit box and in that box the user has to
I have created a user login Dialog Box in MFC, which have two edit
Can we have an edit text box inside our menu which gets displayed in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.