Mailbox address regular Expression validation code collection Script Home Special Edition _ Regular expression

Source: Internet
Author: User
Tags regex expression
e-mail address validation Regular expression

e-mail address verification in Dedecms
Copy Code code as follows:

<?php
$email = "test@jb51.com";
Mailbox Format Check

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);

e-mail address verification in Phpcms
Copy Code code as follows:


function Is_email ($email)
{
return strlen ($email) > 6 && preg_match ("/^[\w\-\.] +@[\w\-\.] + (\.\w+) +$/", $email);
}
echo Is_email ($email);
?>

After testing a@jb51.net such a mailbox Checkemail does not support but is_email support, but for such a mailbox very few people use, so it is also possible. You can choose according to your needs.

the ASP determines whether the e-mail mailbox address is in the correct format
We can solve this problem by using the following methods--but only to be able to determine whether the format of each e-mail address is valid and does not guarantee that the address does exist.

The First approach:

<%
'****************************************************
' Function name: Chkmail
' Function: Mailbox format detection
' Parameters: Email----email address
' Return value: True, False incorrect
'****************************************************
Public Function Chkmail (ByVal Email)
Dim Rep,pmail:chkmail = True:set Rep = New RegExp
Rep.pattern = "([\.a-za-z0-9_-]) {2,10}@ ([a-za-z0-9_-]) {2,10} (\. [A-za-z0-9]) {2,}) {1,4}$ "
Pmail = Rep.test (Email): Set Rep = Nothing
If not pmail Then chkmail = False
End Function
%>
Use:
If chkmail ("ls535427@2221262.com") = True Then
Response.Write "Format is correct"
Else
Response.Write "Wrong Format"
End If

The second approach is to use the following function to determine. It checks to see if the email address contains "@" and "." 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 code 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
<script> function Checkemail (email) {var str=email; In JavaScript, regular expressions can only start and end with "/" and cannot use double quotes var re =/^ ([a-za-z0-9]+[_|\-|\.]?) *[a-za-z0-9]+@ ([a-za-z0-9]+[_|\-|\.]?) *[a-za-z0-9]+\. [A-za-z] {2,3}$/; var objexp=new RegExp (re); if (Objexp.test (str) ==true) {return true; }else{return false; } Alert (Checkemail ("admin@jb51.net")); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

In fact, a lot of code here is from some well-known CMS system, get, like some relatively good function, basically to save time can refer to the source of the mature system reference.
PHP can refer to dedecms phpcms, etc.
ASP can refer to Kesioncms dynamic and other open source system
JS can be more from some sites to download JS view hehe.

More form Validation reference codes
JS common regex expression Form validation 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.