Analysis
A complete domain name, by the root domain, top-level domain, level two, three ... Domain name composition, each level of domain name separated by point, each domain name by letter, number and minus sign (the first letter can not be a minus), case-insensitive, not more than 63.
Obviously, a single name can be matched by a regular expression [a-za-z0-9][-a-za-z0-9]{0,62}, and the complete domain name includes at least two names (such as Google.com, made up of Google and COM), and finally, a point that represents the root domain.
Regular expression that matches the full domain name:
The code is as follows |
Copy Code |
[A-za-z0-9] [-a-za-z0-9] {0,62} (. [A-za-z0-9] [-a-za-z0-9] {0,62}) +.? |
Our simplest version of JS regular filter to take the domain name
Domain name Regular expression JS version
The code is as follows |
Copy Code |
function Doseo () { if (!$ (' domain '). Value.match (/^ ([A-z0-9-]{1,}.)? [a-z0-9-] {2,}. ([A-z0-9-]{1,}.)? [A-z0-9] {2,}$/i)) { Alert (' Hello ~ ~ ~ First, please enter the correct domain name:P '); $ (' domain '). Value = '; $ (' domain '). focus (); Return } |
The above can be used to judge the domain name, then I want to filter the domain name how to see the example
After this friend test, he still prefers this effect (I personally or prefer to remove the space before detection), should he request the source to put out:
The code is as follows |
Copy Code |
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <title> Testing </title> <body> <script language= "JavaScript" > function Checkurl (obj) { var pattern =/cs*os*m|cs*n|ns*es*t|os*rs*g/gi; if (Pattern.test (Obj.value)) { Alert ("There are com|cn|net|org in the message, there is suspicion of advertising links, can not submit!" "); Obj.value = ""; Obj.focus (); return false; } else{ Do what you want to do. } } </script> <textarea name= "Content" cols= "rows=" wrap= "VIRTUAL" id= "content" Onblur= "Javascript:checkurl (this);" ></textarea> </body>
|
Online Find JS filter HTML title code is as follows:
The code is as follows |
Copy Code |
function SetContent (str) { str = str.replace (/</?[ ^>]*>/g, ""); Remove HTML tag Str.value = str.replace (/[|) *n/g, ' n '); Remove line trailing blanks str = str.replace (/n[s| |) *r/g, ' n '); Remove extra blank lines return str; } |
The test found that this code can not filter out the Web page hollow characters (ie: ). So I rebuilt it again:
The code is as follows |
Copy Code |
function Removehtmltag (str) { str = str.replace (/</?[ ^>]*>/g, ""); Remove HTML tag str = str.replace (/[|) *n/g, ' n '); Remove line trailing blanks str = str.replace (/n[s| |) *r/g, ' n '); Remove extra blank lines Str=str.replace (/ /ig, ')/Remove return str; }
|
Well, my request was reached.
So our filter domain name, HTML title and domain name is difficult to get done.