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