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 7841861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:11:22+00:00 2026-06-02T16:11:22+00:00

I am trying to check if an at character only exist in an android

  • 0

I am trying to check if an at character only exist in an android edit-view. I am new to regular expression and i implemented the forthcoming code. where am i mistaken ? Here is my code

try {

        Pattern pattern = Pattern.compile("/@");
        Matcher matcher = pattern.matcher(valEmail);

        if (!matcher.matches()) {

            Toast.makeText(this," Invid no @ character ",Toast.LENGTH_LONG).show();

        }

    }catch(Exception ex){}
  • 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-06-02T16:11:25+00:00Added an answer on June 2, 2026 at 4:11 pm

    There are two problems with your current code:

    • The leading slash means it really is looking for “/@” rather than just “@”. You seem to think that “/” does something special within a regex – it doesn’t.
    • You’re using matches() which tries to match the whole of the input; you want find which will just try to find a match for the regex somewhere in the input.

    Why are you using regular expressions at all though? Why not just:

    if (!valEmail.contains("@")) {
        ...
    }
    

    That will check whether the address contains any “@” signs. If you want to check that there’s only one “@” sign, you could use:

    int atIndex = valEmail.indexOf('@');
    if (atIndex == -1) {
        // Handling for *no* @ sign
    }
    if (valEmail.indexOf('@', atIndex + 1) != -1) {
        // Handling for multiple @ signs
    }
    

    If you do want to use regular expressions, there are rather more sophisticated email address validation regular expressions available. (There lots of different ones with different levels of validity – make sure you get one designed for the Java flavour of regex.) I wouldn’t use one just for this though – only use regular expressions where you’re really interested in pattern matching.

    If you want to use a regex for “at least one non-@, following by @, followed by at least one non-@” you could use:

    // TODO: Compile this once and reuse
    Pattern pattern = Pattern.compile("[^@]+@[^@]+");
    Matcher matcher = pattern.matcher(valEmail);
    
    if (!matcher.matches()) {
        ...
    }
    

    As an aside, this:

    catch(Exception ex){}
    

    is never a good idea. Please don’t just ignore errors indiscriminately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to check if a character belongs to a list/array of invalid characters.
Why linq is trying to check second expression anyway? .Where(t => String.IsNullOrEmpty(someNullString) || t.SomeProperty
I am completely new to regular expressions ,and I am trying to create a
I have been trying to solve a PHP regular expression problem for awhile now
I am trying to apply negation on regular expression in .Net. It does not
I am trying to check if a date has passed or if it is
I am trying to check for locked accounts in AD. In a few snippets
I'm trying to check in jQuery if a div contains some text, and then
I am trying to check if a user is a member of an Active
I am trying to check if I have write access to a specific key

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.