Based on jquery regular authentication URL, email address code

Source: Internet
Author: User
Tags ftp regular expression jquery library

Today, a friend asked me this question, so I intend to post it to share.

In fact, the implementation is very simple, because the regular expression rules are the same, in PHP can be used, so in JS also can be used.

As long as the regular expression is written correctly, half of it succeeds.

The following directly on the code, see it again.

Don't forget to introduce the jquery library.

The code is as follows Copy Code

function Ismessemailok (messemail) {
var a=/w+ ([-+.] w+) *@w+ ([-.] w+) *.w+ ([-.] w+) * * *;
if (!a.test (Messemail)) {
Alert ("Warning: Incorrect mailbox format!");
Here are some other things you can write about, such as resetting a form or something. For example, reset the input box with ID messemail to null below
$ (' #messemail '). Val (');
F.messemail.focus ();
return false;
}else{
return true;
}
}

or directly using JS

It is convenient to use regular expressions, "/^ ([a-za-z0-9_-]) +@ ([a-za-z0-9_-]) + ((. a-za-z0-9_-]{2,3}) {1,2}) $/"the correct mailbox format that meets the requirements.

The code is as follows Copy Code

function Isemail (str) {
var reg =/^ ([a-za-z0-9_-]) +@ ([a-za-z0-9_-]) + (. [ a-za-z0-9_-]{2,3}) {1,2}) $/;
return Reg.test (str);
}

jquery standard network address regular, such as Http://www.111cn.net

The code is as follows Copy Code
function Ismesswebsiteok (messwebsite) {
var a=/(https?):/ /([^./]+)([.]?) ([^./]+) ([.]?) ([^./]+) (/[w-./?%&=]*)?/I;
if (!a.test (Messwebsite)) {
Alert ("Warning: URL format is not correct!");
Here are some other things you can write about, such as resetting a form or something. For example, reset the input box with ID messwebsite to null below
$ (' #messwebsite '). Val (');
F.messwebsite.focus ();
return false;
}else{
return true;
}
}


If you want to have a port or something, use the example below.


The javascript! of the regular expression judgment of this URL More comprehensive. It verifies the situation including IP, domain name (domain), FTP, two-level domain name, domain name files, domain name plus port! User name and so on, looks like the author is also on the Internet, I deducted from a project code, is the strongest I have ever seen the most comprehensive way to verify the URL! Too fierce, posted here to share with you first, later do not remember when to look for a blog, the URL verification is very frequent.

The code is as follows Copy Code

function Isurl (Str_url)

var Strregex = "^ (HTTPS|HTTP|FTP|RTSP|MMS)?:/ /)

+ "? ([0-9a-z_!~* ' (). &=+$%-]+:)? [0-9a-z_!~* ' (). &=+$%-]+@)? " FTP user

+ "([0-9]{1,3}.) {3} [0-9] {1,3} "//IP form of URL-199.194.52.18

+ "|"//allow IP and domain

+ "([0-9a-z_!~* ' ()-]+.) * "//Domain name-www

+ "([0-9a-z][0-9a-z-]{0,61})?" [0-9a-z]. " Second-level domain

+ "[a-z]{2,6}]"///domain-. com or. Museu

+ "(: [0-9]{1,4})?"//Port-: 8

+ "((/?)|" A slash isn ' t required if there is no file Nam

+ "(/[0-9a-z_!~* ' ().;?: @&=+$,%#-]+) +/?" $"

var re=new RegExp (Strregex)

Re.test (

if (Re.test (Str_url))

Return (TRUE)

}else

Return (false)
}

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.