Use regular expressions to verify mailboxes in JS and Java

Source: Internet
Author: User

Question: Do you often check mailboxes in your project?

Mailbox format: The first must be a letter, must contain an @ symbol, and there is a name after @, and then there is a suffix name.

For example: [email protected]

 

First, the code in Java is as follows:

String reg= "[a-z]+[a-z0-9_-]*\\@[a-z0-9]+\\. [a-z]+]; System.out.println ("[Email protected]". Matches (reg));

Explain:

[a-z]+: A letter indicating that at least one or more occurrences of the content is a-z/a-z
[a-z0-9_-]*: Indicates a letter that can occur 0 or any time with a content of a-z/a-z/_/-
\\@: Double slash means the escape character is actually trying to match the @ symbol
\ \.: With \\@

Second, the code in JavaScript is as follows:
    <script type= "Text/javascript" >    var email= "[email protected]";   var reg=/[a-z]+[a-z0-9_-]*\@[a-z0-9]+\.   [a-z]+/;   Alert (reg.test (email));    </script>
Explanation: On the same Java



Note:

[Any one of the 0-9]:0-9
[Any one of the a-z]:a-z
[Any one of the a-z]:a-z
[Any of the a-z]:a-z and A-Z
\d: Digital
\d: Non-digital
\w: Letters
\w: Non-letter
\s: Space
\s: Non-whitespace
n+: A string of at least one n
N: 0 or more N strings
N. occurs 0 or more times
{5} appears 5 times
{2,8}2 to 8 times



Use regular expressions to verify mailboxes in JS and Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.