Email Address Regular Expression Verification Code collection Special Edition

Source: Internet
Author: User
Tags regex expression

Regular Expression for email address verification

Email address verification in dedecms CopyCodeThe Code is as follows: <? PHP
$ Email = "test@jb51.com ";
// Check the email format

Function checkemail ($ email)
{
Return eregi ("^ [0-9a-z] [a-z0-9 \. _-] {1,} @ [a-z0-9-] {1,} [a-z0-9] \. [A-Z \.] {1,} [A-Z] $ ", $ email );
}
Echo checkemail ($ email );

Email address verification in phpcms Copy codeThe Code is as follows:

Function is_email ($ email)
{
Return strlen ($ email)> 6 & preg_match ("/^ [\ W \-\.] + @ [\ W \-\.] + (\. \ W +) + $/", $ email );
}
Echo is_email ($ email );
?>

After testing the@jb51.net such mailbox checkemail does not support but is_email support, but for such a mailbox is rarely used, so it is also possible. You can select as needed.

ASP determines whether the email address format is correct
The following methods can be used to solve this problem-but it is not guaranteed that the format of each email address is valid.

Method 1:

<%
'*************************************** *************
'Function name: chkmail
'Usage: email format Detection
'Parameter: email ---- email address
'Return value: True is correct, and false is incorrect.
'*************************************** *************
Public Function chkmail (byval email)
Dim rep, pmail: chkmail = true: Set rep = new Regexp
Rep. pattern = "([\. a-zA-Z0-9 _-]) {} @ ([a-zA-Z0-9 }(\. ([a-zA-Z0-9]) {2,}) {} $"
Pmail = rep. Test (email): Set rep = nothing
If not pmail then chkmail = false
End Function
%>
Usage:
If chkmail ("ls535427@2221262.com") = true then
Response. Write "The format is correct"
Else
Response. Write "Incorrect format"
End if

The second method is to use the following function for judgment. It checks whether the email address contains "@" and whether "." Is after:
<%

Public Function isemail (byval pstring)
Dim PLT, PGT: PLT = false: PGT = false
For x = 2 to Len (pstring)-1
If mid (pstring, X, 1) = "@" then PLT = true
If mid (pstring, X, 1) = "." and PLT = true then PGT = true
Next
If PLT = true and PGT = true then
Isemail = true
Else
Isemail = false
End if
End Function
%>

Copy code The Code is as follows: <%
Function isemail (strng)
Isemail = false
Dim RegEx, match
Set RegEx = new Regexp
RegEx. pattern = "^ \ W + (-\ W +) | (\. \ W +) * \ @ [A-Za-z0-9] + ((\. |-) [A-Za-z0-9] + )*\. [A-Za-z0-9] + $"
RegEx. ignorecase = true
Set match = RegEx. Execute (strng)
If match. Count then isemail = true
End Function
%>

JS email address verification code
[Ctrl + A select all Note: If you need to introduce external JS, You need to refresh it to execute]

In fact, a lot of code here is obtained from some well-known CMS systems, just like some good functions. Basically, to save time, you can refer to the source code of a mature system for reference.
For PHP, see dedecms phpcms.
ASP can refer to open-source systems such as kesioncms
Javascript can be downloaded from some websites for more information.

Reference code for more Form Verification
Common JavaScript RegEx Expression Form Verification Code

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.