Regular expression--qq micro-letter, cool front-end mailbox Regular expression validation bug_ regular expression

Source: Internet
Author: User
Tags sql injection

Take the mailbox verification, most people on the Internet write the mailbox validation regular expression code can not verify this mailbox:

i@julying.com, nor can you verify xxxxxx@i.com .

Last I found that youku.com (Youku) User registration has this problem, see figure:

Today found QQ micro-letter also has this problem:

Neither of them can verify the name of a domain name or a letter of a letter.

In my opinion, they are not intentionally not to let such a user register, but this:

A long time ago, the first programmer to write a regular was lazy, without the regular expression validation of this situation,

He might have thought it was a bit of a hassle, and maybe there was too little mail,

Did not hear a letter of the top-level domain to provide the mailbox service, also did not see that mailbox username is a letter, so did not write.

And later programmers have been using this code ...

-------------------

Because the program can not handle the location type of data, such as the 2003 network large area burst SQL injection, is a classic case.

As senior Bill Gates said: "All user input is harmful, the programmer should be as far as possible to verify all the possibilities, otherwise, the missing possibility is a potential crisis."

-------------------

I am by the way to write a complete email verification regular expression bar, later do not make such a mistake, people are very depressed.

PHP Mailbox Validation Regular expression:

Preg_match ("/^[0-9a-za-z]+@" ([0-9a-za-z]+) [.]) +[a-z]{2,4}$/i ", $email);

If more complete and rigorous validation is required, modify the regular expression.
PHP Mailbox Validation Regular expression Novice instance:

Copy Code code as follows:

<?php
function Isemail ($email) {
if (Preg_match (/^[0-9a-za-z]+@ ([0-9a-za-z]+) [.]) +[a-z]{2,4}$/i ", $email)) {
Return ' is the mailbox ';
} else{
Return ' not a mailbox ';
}
}
?>

--------------------------------------------------------------------------------
Javascript (JS) mailbox validation Regular expression:
Myreg =/^ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+@ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+\. [A-za-z] {2,4}$/;
This can be verified in the form of: i@julying.com, i@i.com such mailboxes
--------------------------------------------------------------------------------
Javascript (JS) mailbox validates the regular expression novice instance:
Copy Code code as follows:

<script type= "Text/javascript" >
Function Isemail (val) {
var myreg =/^ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+@ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+\. [A-za-z] {2,4}$/;
if (!myreg.test (val))
Return ' not a mailbox ';
Return ' is the mailbox ';
};
Alert (Isemail (' i@julying.com '));
</script>

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.