jquery Email Address URL Site Address regular validation instance code _jquery

Source: Internet
Author: User

Email Address Verification

Copy Code code as follows:

function Checkemail () {
var Email=$.trim ($ ("#report_email"). Val ());
if (email = = "") {
$ ("#report_email"). Next (' P '). HTML ("* Please enter the email address!");
return false;
}
var re =/^ ([a-za-z0-9]+[_|_|.]?) *[a-za-z0-9]+@ ([a-za-z0-9]+[_|_|.]?) *[a-za-z0-9]+. [A-za-z] {2,3}$/ig;
if (!re.test (email)) {
$ ("#report_email"). Next (' P '). HTML ("* Email address format is wrong!");
return false;
}
return true;
}

URL address Verification

Copy Code code as follows:

function Geturlarray (e, type) {
var urls = $.trim ($ ("#report_url_list"). Val ());
URLs = Urls.replace (/s*n+s*/ig, "n");
$ ("#report_url_list"). Val (URLs);
Format the URL
if (type = = "Blur") {
Reporturlelm.val (URLs);
}
if (e && e.keycode = 13) {
Reporturlelm.val (URLs + "n");
}

URLs = Urls.split ("n");
User_urls = URLs;
return URLs;
}
function Checkurls (e, type) {
$ ("#errorList"). Find ("span"). Hide ();
URLs = Geturlarray (e, type);
var urlfag = true;
Url_index = 0;
var urltext= "Please fill in the report site, you can report multiple URLs, one per line, no more than 20." ";
if (!urls[0] | | | urls[0] = = Urltext) {
$ ("#report_url_list"). Val (urltext). CSS ("Color", "#757575");
$ ("#report_url_list"). Next (' P '). HTML (' * Please enter the correct URL ');
$.urlfag=false;
return false;
}
if (Urls.length > 20) {
$ ("#report_url_list"). Next (' P '). HTML ("Over 20, please report in batches")
$.urlfag=false;
return false;
}
$.urlfag=true;
for (url_index=0;url_index<urls.length;url_index++) {
$.urlfag = Checkeachurl (URLs, url_index) && $.urlfag;
}
return URLFAG;
}
function Checkeachurl (URLs, index) {
var e=urls[index];
A = E.replace (/^http:///, "");

if (A.indexof ("/")!=-1) {
A = a.substring (0, A.indexof ("/"));
}
var RG =/^ (https?| Ftp|news)://)? ([w-]+.) +(.) + (:d +)? (/[w-./?%&=]*) $/i;
if (!rg.test (a)) {
Urlerror ("Malformed", index,-1);
return false;
}
if (Inurlarray (Urls,index)) {
Urlerror ("Please do not report the same website", index,-1);
return false;
}
$.ajax ({
Async:false,
URL: "http://api.pc.qq.com/tapi/url_report.php?url=http://" +a,
DataType: "Jsonp",
Method: ' Get ',
Success:function (a) {
if (a.is_existed== "yes") {
Urlerror ("The site has been reported", index,-1);
$.urlfag= false;
}
}
});
Urlerror ("normal", index,0);
return true;
}

function Inurlarray (urls,index) {
var r=false
for (i=index+1;i<urls.length;i++) {
A = Urls[index].replace (/^http (s?):/ //, "");
b = Urls[i].replace (/^http (s?):/ //, "");
if (a==b)
R=true;
}
return R;
}
function Urlerror (msg,index,type) {
type=type| | 0;
var test = $ ("#errorList div"). Find ("span"). EQ (index);
Test.show ();
if (type<0) {
Test.attr (' title ', msg). CSS ("background-position", " -20px 0px");
}else{
Test.attr (' title ', msg). CSS ("background-position", "0px 0px");
}
}

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.