Regular expression — QQ wechat, Youku front end mailbox regular expression verification bug

Time:2021-1-9

Take mailbox verification as an example. Most regular expression codes written by people on the Internet can’t verify this mailbox

[email protected], and cannot be verified[email protected]

Last time I found out youku.com (Youku) user registration has this problem, as shown in the figure below:

 

优酷网 注册 bug

 

Today, we found that QQ wechat has the same problem:

 

QQ微信 bug

 

None of them can verify a one letter domain name or a one letter user name.

In my opinion, they are not deliberately not allowing such users to register, but rather like this:

A long time ago, programmers who initially wrote regular expressions were lazy and didn’t write regular expression verification in this case,

At that time, he might have found it troublesome, and there might have been too few such e-mails,

I didn’t hear that the top-level domain name with one letter provides mailbox service, and I didn’t see that the user name of the mailbox is one letter, so I didn’t write it.

And later programmers have been using this code…..

——————-

Because the program can’t handle location type data, for example, SQL injection broke out in a large area of the network in 2003, which is a classic case.

As Bill Gates said: all the input of users is harmful, programmers should try their best to verify all the possibilities, otherwise, the missed possibility is a potential crisis.

——————-

By the way, I write a complete mailbox to verify regular expressions. Don’t make such mistakes in the future. It’s very depressing..

 

PHP mailbox validation regular expression:

preg_match(“/^[0-9a-zA-Z][email protected](([0-9a-zA-Z]+)[.])+[a-z]{2,4}$/i”,$email );

If you need more perfect and strict verification, you can modify the regular expression.
PHP mailbox verification regular expression novice example:

Copy codeThe code is as follows:
<?php
function isEmail($email){
if(preg_match(“/^[0-9a-zA-Z][email protected](([0-9a-zA-Z]+)[.])+[a-z]{2,4}$/i”,$email )){
Return ‘is a mailbox’;
} else{
Return ‘is not a mailbox’;
}
}
?>

——————————————————————————–
JavaScript (JS) mailbox validation regular expression:
myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9][email protected]([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;
This can be verified as follows: [email protected] ,[email protected] This kind of mailbox
——————————————————————————–
JavaScript (JS) mailbox verification regular expression novice example:

Copy codeThe code is as follows:
<script type=”text/javascript”>
function isEmail(val){
var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9][email protected]([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;
if(!myreg.test(val))
Return ‘is not a mailbox’;
Return ‘is a mailbox’;
};
alert( isEmail(‘[email protected]’) );
</script>